We are going to use Google Cloud Load Balancer with React.js application. React.js application has special routing rules. We are going to organize our application structure in the following way.
-[BUCKET]uiresources
-[FILE]index.html
-[FOLDER]dist
-[FILE]src.bundle.js
-[FOLDER]...
-[FILE]
Also we need to route api calls to GCF endpoints. That means that they should be proxied to another domain, that, seems to be impossible because we configuring backend-service with VM as a target.
Example of routing
- / ---------------------------> /index.html (To storage bucket)
- /index.html --------------> /index.html (To storage bucket)
- /signup -------------------> /index.html (To storage bucket)
- /someroute --------------> /index.html (Still to storage bucket)
- /api/signup ---------------> anotherhost.com/signup (To GCF endpoint with long url)
- /resources/images -----> /resources/images (To storage bucket)
We can say that in another way, like, if our route contain dot, that will mean that we requesting file, then return appropriate file, otherwise always return index.html.
It is possible to use subdomains if it will help to build such navigation. For example:
Another routing example
- https://targetdomain.com/api or https://api.targetdomain.com -> for services call
- https://targetdomain.com/resources or https://resources.targetdomain.com -> - for resources loading including index.html
- https://targetdomain.com/[^index.html] -> for direct routes from browser for which index.html will be returned
So, the question is just how? I setup load balancer using tutorial and tried to configure the rules here, but I didn't have any luck with it. I started from index.html issue and this is what I have at the moment.
Previously I've managed this on Azure and on simple nginx server, but on this two platforms more powerful routes configurations is available. I don't know if it possible here, but hope someone can help me with that.
All the VM instances are running under Debian 8 with Apache server. I though about routing rules inside each VM instance, but for me it looks a little bit crazy now and something that will bring a lot of troubles in the future.