Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.headers['x-forwarded-for'] is missing #16

Closed
newbaluku opened this issue May 9, 2022 · 3 comments
Closed

req.headers['x-forwarded-for'] is missing #16

newbaluku opened this issue May 9, 2022 · 3 comments

Comments

@newbaluku
Copy link

I would usually get the remote IP from value of req.headers['x-forwarded-for'] when my code is running in FC custom runtime.

but when using the Nodejs runtime via the fc-http wrapper, this value is undefined.

it would be good if it can be consistent with the usage of other runtimes like FC custom (I can also get it when running in AWS lambda through the serverless-http wrapper).

if not, what is your advice on how to get it (preferably an official method that will be persistent in future implementations).

@newbaluku
Copy link
Author

newbaluku commented May 11, 2022

@heimanba

did some dig around in the requestContext and found an IP in the requestContext but not sure if this is the official supported variable for Function compute handler.

exports.handler = serverless(app, {
  request(request, event, context) {
    request.context = event.requestContext;

   // is this caller IP?
   console.log('caller IP:', event.requestContext.identity.sourceIp)
  },
})

kindly please advice?

or any other officially supported way?

@newbaluku
Copy link
Author

@heimanba any suggestion?

@heimanba
Copy link
Member

heimanba commented May 13, 2022

event.fcRequest 可以获取默认的 fc的req对象,您可以从 event.fcRequest 对象中获取,当然也可以通过 event.clientIP获取 IP
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants