I’m looking for advice on how to serve two different codebases (both static frontends) from the same domain (for eg. with using workers or pages) while maintaining this URL structure:
Can anyone share best practices or examples on how to set this up, especially concerning configuration and routing? Any help would be greatly appreciated!
codebase1.example.com with codebase 1
codebase2.example.com with codebase 2
and put a worker on example.com that would act as some sort of reverse proxy and if example.com is requested it loads codebase1.example.com, if example.com/:username/:slug is requested it loads codebase2.example.com, right?
what are the limitations of this solution?
one of the codebases will be a vue js single page application (the other one will be a static html site with css and js files so i’m less worried about that). would that work fine just how it should?
oh one more thing! what if I were to add (multiple) custom domains to example.com/:username/:slug - User-specific dynamic pages (codebase 2). how would that be possible?
sure! so as i stated in my example, codebase 2 will handle user-specific dynamic pages with the example.com/:username/:slug scheme. so for example this could be an url to a specific user’s specific post: example.com/laudian/my-post-title-slug.
In the future i’d like to add custom domains for some users, so the above example url could be turned into something like this (with a custom domain): laudian.com/my-post-title-slug. but that would still point towards the content that can be reached on example.com/laudian/my-post-title-slug. afaik, I should add an A record for the custom domain with the server’s IP, but how would I go about knowing what to serve ?
You would use Cloudflare for SaaS to route the custom domain through your Cloudflare zone.
Then you would create a Worker Route that routes the hostname to your Worker.
You can either create a new Worker for every custom domain, or you can handle rewriting the requests within a single Worker. But you’d have to write that logic yourself.