'Apollo and Express report source ip in different formats, how to normalize?

I am using nestjs and have a few REST controllers as well as Apollo GraphQL queries/mutations.

In my REST controller, I am using @Request() request with Request imported from @nestjs/common. request.ip is reported as ::1

In my graphql guard, I have the following code:

  async canActivate(context: ExecutionContext): Promise<boolean> {
    {
      const ctx = GqlExecutionContext.create(context);
      const request = ctx.getContext().request;

and request.ip = ::ffff:127.0.0.1

I need to make sure requests from GraphQL and REST both report the ip address in the same format. Any ideas how to make this happen?

Thanks

Paul



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source