Skip to content

Commit 08d656e

Browse files
committed
feat: detect callerIP in registry
1 parent 76d62cf commit 08d656e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/modules/service-registry/controllers/service-registry-grpc.controller.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ServerUnaryCall } from '@grpc/grpc-js';
2-
import { Metadata } from '@grpc/grpc-js';
1+
import type { ServerUnaryCall, Metadata } from '@grpc/grpc-js';
32
import { Controller } from '@nestjs/common';
43

54
import { ApiConfigService } from '../../../../src/shared/services/api-config.service';
@@ -16,22 +15,25 @@ export class ServiceRegistryGrpcController implements ServiceRegistryGrpcControl
1615
private readonly apiConfig: ApiConfigService,
1716
) {}
1817

19-
async registerService({
20-
heartbeatDurationInSec,
21-
type,
22-
url,
23-
region,
24-
}: registerServiceRequest): Promise<registerServiceResponse> {
18+
async registerService(
19+
request: registerServiceRequest,
20+
_metadata: Metadata,
21+
call: ServerUnaryCall<registerServiceRequest, registerServiceResponse>,
22+
): Promise<registerServiceResponse> {
2523
try {
24+
const { heartbeatDurationInSec, type, region } = request;
25+
2626
const serviceTypeKey = ServiceTypeEnum[type];
2727

2828
if (!serviceTypeKey || !(serviceTypeKey in ServiceType)) {
2929
throw new Error(`Invalid service type: ${type}`);
3030
}
3131

32+
const callerIp = call.getPeer();
33+
3234
const { token } = await this.serviceRegistryService.register({
3335
heartbeatDurationInSec,
34-
url,
36+
url: callerIp,
3537
type: ServiceType[serviceTypeKey as keyof typeof ServiceType],
3638
region,
3739
});

0 commit comments

Comments
 (0)