5

I have a single page application that I am (trying) to host on Google Cloud Storage.

The application is at index.html, and the application handles routing using Angular's html5Mode. (e.g.: routes like example.com/this and example.com/that are handled by the js application in index.html)

Using Google Cloud Storage's website configuration this is all well and good, except that routes that are accessed directly ("example.com/this") will 404 as they obviously do not map to a file.

I have set my 404 page to be my index page, but what I really need in order to run a single page application in html5Mode is that such routes ("example.com/this") will not return a 404 header - they will simply be handled by index.html and return a success header (200).

Is this possible?

  • I ran into the same problem and have the liberty of using S3 as an alternative and using [redirection rules](https://stackoverflow.com/a/16877231/51280). – opyate Aug 24 '17 at 12:13

2 Answers2

5

Setting index.html to your 404 page from the website configuration seems to do the trick now.

enter image description here

Tola
  • 569
  • 7
  • 14
  • 3
    No idea why this was downvoted as the user was so friendly to not leave a comment, but this worked perfectly for me. – RobbyD Nov 09 '17 at 11:41
  • 1
    Maybe because the question specifically asks for a solution that returns a 200 status, not a 404. – Ron Inbar Nov 24 '22 at 16:01
2

Unfortunately, this isn't really possible. Google Cloud Storage's web mapping is pretty simple, and you can't create arbitrary rules based on patterns and the like.

You might want to consider either disabling html5mode or forcing a hashbang with html5mode. See this answer for more on that option.

Community
  • 1
  • 1
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145