pages.dev tunnel
I have a Cloudflare tunnel with ingress rules like:
essentially, i want
/api/*
traffic to go to the NodeJS server, then other traffic forwarded to Cloudflare pages.
is this not supported? or is there a right way to do it?11 Replies
oh it just occurred to me that a Page Rule is probably the right way
I would probably go with Workers Assets instead of Pages
You can deploy it as a route over
xyz.example.com
, then create a second route that covers xyz.example.com/api*
, and set it to not have a Worker at allooh nice!
what's the benefit of the 2nd route? won't the first route be a catch all?
That's the point. The first route sends all requests to
xyz.example.com
to your Worker. Then, the second rule says that, if the URL is xyz.example.com/api*
, bypass the Worker and send it to your backendyou're interchanging "rule" and "route" so i'm a bit confused :)
Sorry about that. I meant Routes
Basically, your Workers Routes for
example.com
would look like:
gotcha. and i assume the cloudflare tunnel will take care of the rest?
Yep. Theoretically, you shouldn't even need the
path
matching in your config
Also note if you want a visual editor, you can make changes to your Tunnel config via the Zero Trust Dashboardappreciate the tip. i'm using pulumi though :)
it's a bit troublesome of a configuration, only because i use Vite for my web app in development, proxying any
/api/*
traffic to the wrangler dev
process. whereas, your proposed setup inverts that relationship.. do you know if @cloudflare/vite-plugin
would help "normalize" the dev setup to mirror the production one? if not, that's fine. i'm sure i can survive :)
to clarify, is there a recommended setup for development whereby the Workers Assets are served by ViteWait, I'm confused. Wasn't it the other way around?
That
/*
was wrangler dev
, and /api/*
is whatever secondary backend?i'm using a bit of an esoteric setup for a staging environment that i won't get into the details of...
but yes, that's what you just helped with, and now i'm curious if i can do the opposite in development, since my web app is using Vite. but i think i can answer that myself, since my dev worker can simply redirect non-API traffic to the Vite dev server.
this is what i get for being fancy