4

I'm automating deployment of a single page app that uses client side routing using GCP. So far, cloud build successfully builds my site and deploys the static assets to a bucket. A load balancer points at the bucket and I can successfully access my site over https at the correct url. I configured the specialty pages of the bucket so that 404's go to index.html, and this technically works as expected, but it returns a 404 error code instead of a 200. How should I configure url rewrites so that every request serves index.html as a 200? I see the load balancer has some sort of url rewriting, but the GCP docs are pretty unclear on how I could use this like I have described. I'm hoping the answer is not "deploy an nginx container as a reverse proxy". There has to be a simpler way, ideally that I can just configure via the GCP console.

Noohone
  • 694
  • 5
  • 12
Rob Allsopp
  • 3,309
  • 5
  • 34
  • 53
  • Do you want to redirect all requests to the index page even If the requested file doesn't exist and return a 200 error code instead of a 404? – Khalid K Jul 23 '20 at 20:43
  • Sure do. The only html file that exists is index.html (its an SPA), and a request for either mysite.com or mysite.com/cool/stuff/omg/wow should both return index.html with a 200. index.html handles all routing and will do its own 404 displaying. – Rob Allsopp Jul 23 '20 at 23:05
  • In case of a 404 error code you are redirecting the traffic to a static web [page](https://cloud.google.com/storage/docs/hosting-static-website) hosted in a bucket, but in the same time you want to return a 200 error code instead of a 404. Cloud storage and the HTTP(s) load balancer don't have this conditional capability. Also URL rewrites are only used to make URLs more easy and simplified for users. – Khalid K Jul 27 '20 at 19:03

0 Answers0