Setting `upstream` hardcodes hostname of incoming request.
Hi there,
upstream is a very useful option for testing middleware, but I believe it has a bug that hardcodes the incoming request hostname to the upstream hostname.
const mf = new Miniflare({
upstream: "https://some.example.com"
})
await mf.dispatchFetch("https://www.example.com/api")
In my worker, I expect to see request.url = www.example.com/api and if the request is unhandled by the Worker, then Miniflare will fetch https://some.example.com/api.
However, request.url = some.example.com/api, even though I'm dispatching https://www.example.com/api. Am I misunderstanding how upstream works or is this a bug? I suppose a workaround is to mf.setOptions the upstream to request.url in every test, but this feels cumbersome.
Hey! 👋 There are a few things that make this difficult.
Cloudflare Workers don't have an upstream option per-se. If you fetch https://www.example.com/api on a deployed worker, and the request is unhandled, the runtime will fetch https://www.example.com/api. There's no way to customise the fallback URL.
For Miniflare's CLI, we can't rely on request's hostnames as it will usually be localhost. This is why the upstream option exists.
For Miniflare's API, you're already required to specify the full URL, so can set whatever host you want. This is to say the upstream option doesn't really make sense in the API context, and should probably be set to undefined.
I see this is pretty confusing, so we should probably clarify this in the docs.