Alexander Trauzzi
Alexander Trauzzi

Reputation: 7396

Can I change the status code used for the NotFoundPage in google cloud storage?

It looks like when Google Cloud Storage serves the desired object for a NotFoundPage, it includes the status code 404.

Is there any way to set it so that the content is served with a 200 status? This will make it easier for any single page applications I deploy to the bucket to manage their own deep linking.

Upvotes: 2

Views: 912

Answers (2)

cometfish
cometfish

Reputation: 545

I managed to fix the status code on a Flutter SPA by using the Load Balancer's Advanced Routing Rules:

  • Edit the Load Balancer
  • Click Routing Rules
  • Change Mode to "Advanced host and path rule"
  • Click ADD HOST AND PATH RULE
  • Enter * for the Hosts field
  • Enter the following, depending on your URL format - eg. if the URL I want to rewrite/fix status code on is formatted as: website.com/products/12345/my-amazing-product then I would enter:
defaultService: projects/{..your-project-name..}/global/backendBuckets/{..your-backend-name..}
name: products
routeRules:
- matchRules:
  - pathTemplateMatch: /products/*/*
  priority: 10
  service: projects/{..your-project-name..}/global/backendBuckets/{..your-backend-name..}
  routeAction:
    urlRewrite:
      pathTemplateRewrite: /index.html

Thanks @Alexander Trauzzi for linking the Google issue - comment #48 there gave me the idea to try the advanced routing.

Upvotes: 1

Alexander Trauzzi
Alexander Trauzzi

Reputation: 7396

It appears as though this is currently a feature request over at the Google Cloud issue tracker: https://issuetracker.google.com/issues/151212194

I encourage anyone who arrives here to head over there and star the issue and also comment to help get this some priority.

Upvotes: 3

Related Questions