We have a CF worker set up in front of our domain using a route trigger. This means that any requests to our domain go through the worker.
However I’m not sure how I can test the worker locally (using wrangler), as when I run the worker locally using wrangler dev, when I navigate to 0.0.0.0:8787 I just see this:
Hey Erisa,
I did try that but the behaviour is the same. I think it has something to do with the fact that requests to this worker in prod come in via route bindings which is not the case during development.
I’ve found that I can “emulate” the production behaviour by doing something like this:
addEventListener('fetch', (event) => {
let request = event.request
// Mimic behaviour of worker in prod
if (ENVIRONMENT === 'development') {
const url = new URL(event.request.url)
url.hostname = 'myproddomain.com'
request = new Request(url, request)
}
event.passThroughOnException()
event.respondWith(handleAndLogToHoneycomb(event, request))
})
However, it doesn’t feel right as I can’t truly test what happens in prod without deploying to prod (and potentially breaking all requests to our domain in the process )