Hi folks, I'm trying to speed run a
Hi folks, I'm trying to speed run a prototype with Workers on top of my existing local stack. Basically I want to simulate normal traffic serving, but only a subset of my traffic routes should go to Workers. Is there an off the shelf pattern I can use for doing this reverse proxy in front of my existing stack?
10 Replies
(Again, this is against my localhost stack. A prod-like env will be another beast.)
Maybe within the Worker, have something like this?
Suppose I have my local stack running at the url:
my-local.dev:1234
and I want the worker to handle:
my-local.dev:1234/foo & my-local.dev:1234/bar
And it should reverse proxy all other URLs. What would that config look like?
Thanks btw!
Are you using a Router already?
Where "my-local.dev" is just a localhost mapped DNS record
No, brand new to Cloudflare! We currently use Cloudfront, and I'll be testing out a switch to cloudflare if this is successful.
Ok, so the naive way is to just check the path of the incoming request directly, like This works for one or two routes, but doesn't scale very well
It also sends stuff like
/foobar
to your Worker, which may not be what you wantWhere does the
fetch
call proxy to?
Eg, if I have the worker listen on the 1234
port above, I'd need to map my local stack to 1235
(for example).
Do I configure the upstream domain, or do I need to edit the req.url?I believe you can point it to a local service with
--local-upstream
Cloudflare Docs
Commands - Wrangler · Cloudflare Workers docs
Create, develop, and deploy your Cloudflare Workers with Wrangler commands.
Thank you! I've got some stuff rolling. One more Q: If I want it to fetch some upstream data, how do I have it load that and cache it in the background?
Eg, our build system generates a manifest that I'd like to cache locally (ideally I'd refresh this periodically).