Imagine we have code like this in the NestJS. No matter if it's Guard
or Interceptor
.
In general the place that you have access to ExecutionContext.
import { CanActivate } from "@nestjs/common";
export class MyCustomGuard implements CanActivate {
constructor() {}
async canActivate(context: ExecutionContext): Promise<boolean> {
const ctx = context.getType();
if (ctx !== "rpc") return true;
const rpc = context.switchToRpc();
// ip validation
return true;
}
}
How can i get client ip address in grpc context?