Wrangler dev: host name changes

I have a worker that sniffs the request hostname and does work based on that (our customers each get their own hostname that they cname to us).

That works fine in production, but when I try running locally using wrangler dev, every request comes through with the hostname replaced with edge-request-handler.webrender.workers.dev. Nomatter how I ask for it, 127.0.0.1:8787, localhost:8787, madeuphostfileentry.cfworker:8787, the host part gets rewritten before my worker sees it.

Can somebody confirm whether this is intentional and if so, how to work around it so that I don’t have to do my testing in production?

Hi there,
I’m afraid that indeed you might encounter different behavior between the Worker running in production and you local environment or the preview.
This is expected:

It’s because “wrangler dev” doesn´t emulate the production environment.

But it can be solved easily.

First, you’ll need to customize your “wrangler.toml” to set the actual environment to development, and then create a production environment.

name = "yourdomain"
workers_dev = true

[env.production]
route = "yourdomain.com/*"
name = "yourdomain-production"

Doing this you’ll be able to test both, the production environment using wrangler dev --env production and the development environment using just wrangler dev.