Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy SPA application on Google Cloud Storage using Load Balancer and CDN

I'm investigating a way of deploying an Angular or React web application on Google Cloud using GCS, Load Balancer, and CDN.

I've set up the LB and the GCS using the urlRewrite, but since the LB does not allow full URL rewrite only pathPrefixRewrite, I cannot redirect all the requests to /index.html

I want to achieve the same functionality as firebase hosting where you can specify the rewrite rules

"rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

Another option will be to set the 404 page as index.html, but that will result in a 404 status code return by the server, which I don't like.

Is this possible with Load Balancer, because they are not supporting a full rewrite?

like image 517
Razvan Bretoiu Avatar asked Mar 17 '26 12:03

Razvan Bretoiu


1 Answers

It's now possible with the global external load balancer routing rules to rewrite every cloud storage request to serve the index.html.

defaultService: projects/xxxx/global/backendBuckets/dashboard
name: path-matcher-1
routeRules:
- matchRules:
  - pathTemplateMatch: /**
  priority: 10
  service: projects/xxxx/global/backendBuckets/dashboard
  routeAction:
    urlRewrite:
      pathTemplateRewrite: /index.html
like image 124
David Spiess Avatar answered Mar 20 '26 04:03

David Spiess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!