From 08d656e17922b09350b42a287b08a77856f5c6f9 Mon Sep 17 00:00:00 2001 From: ZigBalthazar Date: Fri, 13 Dec 2024 20:20:39 +0330 Subject: [PATCH] feat: detect callerIP in registry --- .../service-registry-grpc.controller.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/modules/service-registry/controllers/service-registry-grpc.controller.ts b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts index 5b6ffda..d1e153d 100644 --- a/src/modules/service-registry/controllers/service-registry-grpc.controller.ts +++ b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts @@ -1,5 +1,4 @@ -import type { ServerUnaryCall } from '@grpc/grpc-js'; -import { Metadata } from '@grpc/grpc-js'; +import type { ServerUnaryCall, Metadata } from '@grpc/grpc-js'; import { Controller } from '@nestjs/common'; import { ApiConfigService } from '../../../../src/shared/services/api-config.service'; @@ -16,22 +15,25 @@ export class ServiceRegistryGrpcController implements ServiceRegistryGrpcControl private readonly apiConfig: ApiConfigService, ) {} - async registerService({ - heartbeatDurationInSec, - type, - url, - region, - }: registerServiceRequest): Promise { + async registerService( + request: registerServiceRequest, + _metadata: Metadata, + call: ServerUnaryCall, + ): Promise { try { + const { heartbeatDurationInSec, type, region } = request; + const serviceTypeKey = ServiceTypeEnum[type]; if (!serviceTypeKey || !(serviceTypeKey in ServiceType)) { throw new Error(`Invalid service type: ${type}`); } + const callerIp = call.getPeer(); + const { token } = await this.serviceRegistryService.register({ heartbeatDurationInSec, - url, + url: callerIp, type: ServiceType[serviceTypeKey as keyof typeof ServiceType], region, });