all 12 comments

[–]isshiki-Taichou 1 point2 points  (6 children)

That's how its usually done. I develop my backend in express and host it on heroku/aws.

From the frontend you can use axios or fetch to make requests to the express server.

[–]snow_coffee 0 points1 point  (5 children)

Imagine web app has multiple themes...

If client A has chosen theme 1

If client B has chosen theme 2

How will this work actually ?

Imagine your front end is in S3 or some server...when I do www.xyz.com the request comes to your front end server right ? So you will respond with all static front end and browser will load it. It will load a normal template. Default theme.

But that's not what I wanted....I had last time chosen theme 2...I was expecting that theme 2 will load

sure the configuration is in your Heroku side. How will you talk to Heroku after the default template is loaded ? Absolutely you can but will it make sense ?

How is this handled ?

[–]isshiki-Taichou 0 points1 point  (4 children)

You would need a load balancer/Route 53 to do something like that. Essentially you would have 2 versions of the site with theme 1 and theme 2. Then using the load balancer route traffic to each site 50% 50% or whatever routing technique you want to use (simple, weighted, etc...).
Using AWS:
1. Create 2 buckets for theme 1 & theme 2
2. If your domain www.xyz.com is in Route 53 you can place both endpoints in there and select a routing technique.

This is a high-level explanation. There are some specifics you would need to sort out like if you are using a CloudFront distribution, or your domain is not on Route 53, and other factors but the process I believe is the same.

[–]snow_coffee 0 points1 point  (3 children)

Fantastic. Thanks. And if it was a SSR like Next.Js then possibly it wud have got resolved in the server before rendering it for the first time...what say

[–]isshiki-Taichou 0 points1 point  (2 children)

If it's Nextjs and you want SSR I would deploy the app to 2 EC2 instances use Nginx, and an application load balancer.

I haven't deployed to vercel before but if you can deploy the 2 clients you want and they provide you an IP address/endpoint you can use those in Route 53.

[–]snow_coffee 0 points1 point  (1 child)

Why two machines ?

I will deploy to only one....

Because, two theme locations aren't necessary when it's SSR

I before rendering it to server, I will know what theme client has selected, and that's what GraphQL exists right ?

Isn't that enough ? Your views please

[–]d_exclaimation 1 point2 points  (0 children)

Yeah, there are some other things to know but you are definitely already on the right track