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

Option to intercept requests before firing event #40

Closed
wtuzza opened this issue Sep 9, 2021 · 2 comments
Closed

Option to intercept requests before firing event #40

wtuzza opened this issue Sep 9, 2021 · 2 comments

Comments

@wtuzza
Copy link

wtuzza commented Sep 9, 2021

Hey!

I've stumbled upon a possible issue, Currently if the upstream option is set the incoming host header isn't being used. We use a single worker for multiple subdomains, but still need the correct upstream URL. So we need to fetch the subdomain from the incoming request and use it as the subdomain on the upstream URL.

With dollarshaveclub/cloudworker we had to create our own HTTP server so this could be handled easily, But now we are using the server built into MiniFlare which handles things slightly different to our use case.

If we are able to modify the incoming request just before this.dispatchFetch is called it would solve our problem. As long as we had access to the original incoming request and the new request that get's passed to the worker

https://github.com/mrbbot/miniflare/blob/8010e3321d7913a206839e683ef469c22df5aedb/src/index.ts#L416

@mrbbot
Copy link
Contributor

mrbbot commented Sep 9, 2021

Hey! 👋 For the next major version of Miniflare, I'm planning on extracting out the Node request to Request object logic here: https://github.com/mrbbot/miniflare/blob/8010e3321d7913a206839e683ef469c22df5aedb/src/index.ts#L336-L402

This will make it much easier to build custom HTTP servers to handle this scenario. I'm planning to release this in the next few weeks... 🤞 (for now, you could probably copy this code into your own application and create your own HTTP server that way, assuming you're not using WebSockets)

@wtuzza
Copy link
Author

wtuzza commented Sep 10, 2021

Awesome! I've created my own server for now as we don't terminate WS in the worker, We just pass it onto the origin. I look forward to the above update 😁

@wtuzza wtuzza closed this as completed Sep 10, 2021
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