lagonapp / lagon

Deploy Serverless Functions at the Edge. Current status: Alpha
https://lagon.app
GNU Affero General Public License v3.0
1.32k stars 62 forks source link

Forward IP to `Request` #209

Closed QuiiBz closed 1 year ago

QuiiBz commented 1 year ago

In both CLI and Serverless, there is no way to get the user's IP. We should inject it as a header to each Request. Not sure what's the proper header name to use for this, maybe X-Real-IP?

cyco130 commented 1 year ago

Here's how some other runtimes and deployment platforms handle this:

HatTip uses the following convention for Node and Vercel Serverless:

For Bun, currently it only uses X-Forwarded-For.

Personally I'd recommend using either the X-Forwarded-For header which is non-standard but commonly used, or the by directive of the Forwarded header which is standard but quite uncommon.

But you may also consider passing a second parameter to the handler function like many of them do. Possible use cases:

QuiiBz commented 1 year ago

Thanks for the investigation! It's interesting to see how other runtimes handle it and makes me think that (maybe) it should be standardized with WinterCG?

I do prefer the idea of having a header to grab the IP, since it's the most logical one: Request contains all information about a request, and the IPs of the client/proxies are also commonly transferred through the headers. X-Forwarded-For seems to be heavily used compared to Forwarded / X-Real-IP so it should be the most logical one to use.

About passing a second parameter to the handler, it doesn't have any use cases now or in the future. We plan to use the global Lagon object to access more specific APIs.