Worker on existing website

I have an existing website at www.example.com hosted outside cloudflare and I need a worker to respond to 2 endpoints at www.example.com/foo and /bar Is that possible and where might I find docs specific to it?
6 Replies
Walshy
Walshy2mo ago
you'd need the DNS to resolve to Cloudflare or you'd need to do a hacky thing at origin where it then invokes Workers but that kinda ruines the point haha
bnason
bnason2mo ago
The DNS does currently resolve to Cloudflare but using the CNAME method since Cloudflare is not our primary DNS server (yet we are working on moving it over) So if I'm using a Nuxt project and I deploy that using Wrangler. Normally I'd set a custom domain, but would that then takeover the entire domain using that method? Or would it know only the routes for the Nuxt project? I do see the Workers Routes page under the domain so I assume I'd manage it that way and not specify a custom domain?
Walshy
Walshy2mo ago
correct yeah, routes is what you're looking for, you can setup www.example.com/foo* to handle only requests starting with /foo
bnason
bnason2mo ago
Awesome! Also, could I intercept ALL 500 errors on all sites and modify the response from my worker?
Walshy
Walshy2mo ago
You can't match on status code with Workers but this sounds ideal for: https://developers.cloudflare.com/rules/custom-error-responses
bnason
bnason2mo ago
Is that visible in the web ui or just an api level feature? Ah I see I can set a url for 500 Class Errors under Custom Pages
Want results from more Discord servers?
Add your server