I want to understand how local development works for Workers and KV

Hi, I’ve been working for a while on a couple of CF Workers, using them to intercept requests, access KV, and return the response to the client.

In production, we can set a set of routes that will be driven to the Worker, then we perform a fetch to the origin and return a response. All is good here.

My question is about localhost. How do you work here? When running wrangler dev, you get a localhost website that returns 404. Is there a way to redirect this to a real domain or server?

When using wrangler dev, the fetch function goes to the same domain (localhost), which leads to an infinite loop.

When using wrangler dev --remote, the fetch goes to the worker route [worker-name].[account-name].workers.dev. Which is fine as it removes the problem with an infinite loop. But that domain is always leading to a 404 page.

I want to use CF Worker as a proxy, reading keys from KV to append query parameters or headers. How will you work on this locally?

I really appreciate your help


Okay, I made a small breakthroug. I found that I can use the wrangler.toml configuration to define the [dev] host

host = "localhost:8080"

This way I can define which is the destination host :slight_smile: