How do I get the real user ip when using graphl, kubernetes and docker?

3/19/2020

I am trying to get the real ip of the user visiting my website - for statistic on individual users. Currently I can only see the docker ip.

The project is set up with kubernetes, docker and uses graphql for the requests. I have not set it up, why I am not sure on how these interact with each other and exactly where the problem lies.

@Module({
  imports: [
    ConfigModule,
    GraphQLModule.forRootAsync({
      inject: [ConfigService],
      useFactory: () => ({
        autoSchemaFile: 'schema.gql',
        debug: true,
        fieldResolverEnhancers: ['guards'],
        formatError: (error: GraphQLError): GraphQLFormattedError => {
          return error.originalError instanceof BaseException
            ? error.originalError.serialize()
            : error;
        },
        context: ({ req }): object => {
          console.log("Ip:", req.ip); // Prints the docker ip, not the real user ip
          return ({ req });
        },
      }),
    }),
    ...
  ],
  controllers: [AppController],
  providers: [AppService],
})
-- Atonic
docker
docker-compose
graphql
ip-address
kubernetes

0 Answers