-
Notifications
You must be signed in to change notification settings - Fork 204
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
[Feature Request]: Intercept requests made by the worker #32
Comments
Hey! 👋 Workers themselves are basically middleware. You could do the header stripping yourself in your worker script: addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const headers = new Headers(request.headers);
headers.delete("CF-Ray");
// ...and other headers
return fetch(request, { headers });
} If you only wanted to remove headers during development, you could either use the define option (e.g. https://webpack.js.org/plugins/define-plugin/, https://esbuild.github.io/api/#define) of your build tool (if you're using one) or add a custom binding: $ miniflare --binding __MINIFLARE=true addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const headers = new Headers(request.headers);
if (globalThis.__MINIFLARE) {
headers.delete("CF-Ray");
// ...and other headers
}
return fetch(request, { headers });
} We create a new |
Should have thought of that haha. Let me do some testing :-) Btw do you have github sponsors or something similar? |
Not at the moment, but I might look into it in the future. |
Hey! First thanks for this awesome project, We are currently using the one from dollar shave club but that project died :-(
We need a way to strip the added Cloudflare headers added in MiniFlare as it causes Cloudflare to block the request. We need to route to our upstream via cloudflare as there is no direct access to the servers.
So one thought was a way to have some sort of middleware we can write to strip the needed headers to make it work
Or maybe there can be an option to not add any CF headers when the worker makes fetch requests.
Looking forward to hearing your opinion!
The text was updated successfully, but these errors were encountered: