Skip to content

Commit

Permalink
feat: detect callerIP in registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Dec 13, 2024
1 parent 76d62cf commit 08d656e
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 1 in src/modules/service-registry/controllers/service-registry-grpc.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

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

Run autofix to sort these imports! (simple-import-sort/imports)
import { Controller } from '@nestjs/common';

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

async registerService({
heartbeatDurationInSec,
type,
url,
region,
}: registerServiceRequest): Promise<registerServiceResponse> {
async registerService(
request: registerServiceRequest,
_metadata: Metadata,
call: ServerUnaryCall<registerServiceRequest, registerServiceResponse>,
): Promise<registerServiceResponse> {
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,
});
Expand Down

0 comments on commit 08d656e

Please sign in to comment.