Search code examples
cloud-foundrysap-cloud-platform

HTML5 Application (Cloud Foundry) - 404 Not Found nginx


I deployed a React-Application with the Staticfile Buildpack to Cloudfoundry on the SAP Cloud Platform which has different routes (e.g."/login", etc.)

When I access the app with the provided URL (e.g. "www.exampleurl.com") and navigate through my app everything works, the different pages with different routes are working as expected.

My problem now is that, everytime I want to reload a page or if I want to access the application with an additional path attached initally e.g "www.exampleurl.com/todo-route" instead of just "www.exampleurl.com/" I get an 404 Not Found nginx error.

Is this problem related to the application router I need to configure before deploying my application or is it something different. Unfortunately, I am not getting smarter from reading the documentation and resources on this are very rare in general.

I would appreciate some advice very much. Thank you in advance.


Solution

  • For people having trouble with single-page applications as well:

    I found an answer already myself. Refering to this post: Deploy single page application Angular: 404 Not Found nginx

    You need to add a "Staticfile" file in your dist or build folder with "pushstate: enabled". You can also refer to the cloudfoundry documentation for the staticfile buildpack: https://docs.cloudfoundry.org/buildpacks/staticfile/index.html

    Hope that will help some people on the way.