Advice on serving two static frontends from one domain with specific URLs

For Workes & Pages, what is the name of the domain?

example.com

What is the error number?

0

What is the error message?

.

What is the issue or error you’re encountering

don’t know how, need advice

What steps have you taken to resolve the issue?

post to this forum

What are the steps to reproduce the issue?

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:

•    example.com - Main webpage (codebase 1)
•    example.com/:username/:slug - User-specific dynamic pages (codebase 2)

Can anyone share best practices or examples on how to set this up, especially concerning configuration and routing? Any help would be greatly appreciated!

Origin override, available on Enterprise, is able to do this.

Otherwise, you can put both of the sites on different hostnames and use a Worker to decide which site is served for any specific request:

1 Like

so basically i would setup

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?

Right.

Workers cost money if you cross a threshold. Other than that, what kind of limitations are you talking about?

1 Like

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?

That should work.

1 Like

thanks , will try this then

ps. gorgeous cat!

3 Likes

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?

I don’t think I understand your question. Can you give an example?

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.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.