-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat(Worker): add cf-* headers to request #21
Conversation
Hi, thanks for the pr. If you can fix the IP address thing I’ll merge it :-). Any thoughts on how to do https? |
@gja thanks for the feedback. I don't know if I have this quite right yet. I've added a buildRequest function in server.js and moved all the request building logic in server.js and worker.js to that method. The function takes the express request as it's only argument. It's a tricky refactor because of the dependency shift. Building the request for the fetch event needs the ip, etc. I'm wondering if the worker spec should take a dependency on |
headers: req.headers, | ||
function buildRequest(req) { | ||
const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`; | ||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress.split(':').pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req.connection.remoteAddress.split(':').pop()
pro: no additional dependencies
con: there are more robust options
Good points. I think it does make sense to keep the logic in the worker instead of in the server. Primarily because the worker should be more reusable. Is it possible to keep the API signature of worker the same? (taking url and opts). But the Headers are added by the worker. opts.remoteAddress can have the value of node.connection.remoteAddress. Let me know if you'd like me to pick this up as well, I have a bit of bandwidth tonight. |
Thanks @gja, I'm happy to keep plugging away at it but if you have bandwidth and want to pick this up, please go ahead. I think you have a clearer vision for how this should be implemented. I'll probably be able to get back to this in the next few days. |
#17