Custom Routes - Best Practice for Workers as Microservices

Hi all - I am looking for someone to explain the best practice around setting up workers and domains. I am building a saas app with individual services. I have an auth service, data service, etc... I want to have them all sit on api.myapp.app/auth, api.myapp.app/data. I also want api-dev, api-stage subdomains. I have tried to assign a custom route to the service, but it doesn't work and in a way I am not surprised, because I don't have anything anchoring to my subdomain in the way I would have Nginx or even a load balancer in AWS. So, the question is, is there a way of having each service sit on a subroute of api.myapp.app, or do I need to setup a worker to act as a proxy for the other individual services, with the custom domain attached to it? My reticence with this is because every request I receive will essentially invoke two worker calls when it really should only need one. I have to believe there is a better way to do this! Thanks for all advice
2 Replies
Isaac McFadyen
Isaac McFadyen9mo ago
So if you specify a route, you'll need to have a DNS record at that subdomain. An AAAA record of 100:: is usually used (it's just a dummy record that allows the request to be handled by Workers or other Cloudflare services).
dog1283
dog1283OP9mo ago
Thanks, Isaac. Let me try that! Amazing - that worked, thanks, Isaac!
Want results from more Discord servers?
Add your server