0

I'm trying to deploy a React PWA with React Router to a subdirectory in cloudfoundry. After following the instructions, I get the index.html file for every route, including my static files. I'd like for the index.html file to be the fallback instead of the first choice.

Directory structure:

build/
 Staticfile
 nginx/
  conf/
   includes/
    push_state.conf    
 my_subdirectory/
  foo/
   bleh/
    script.js
  bar/
   blah/
    file.css
  index.html

According to the documentation here: https://docs.cloudfoundry.org/buildpacks/staticfile/index.html and this post, Push state enabled & context path routing: Static assets are not found on the server I should have the following Staticfile:

root: my_subdirectory
pushstate: enabled
location_include: includes/*.conf

and .conf file:

location /my_subdirectory/ {

    if (!-e $request_filename) {
      rewrite ^(.*)$ /my_subdirectory/ break;
    }

    index.html;

}

but I still get the index.html file for every route, including the static files. Any guidance is appreciated. TIA.

Joe
  • 191
  • 1
  • 3
  • 13
  • Try removing `pushstate: enabled` from your Staticfile. You're manually configuring pushstate support, so you don't want this or the buildpack is going to add in it's default support too which will likely conflict with what you're adding in custom. – Daniel Mikusa Aug 25 '20 at 16:22
  • Otherwise, it looks ok, the `if (!-e $request_filename)` is going to only fire when the file doesn't exist. So it should be passed over for your static files and only fire for paths that don't exist. If it's still broken, `cf ssh` into your app and pull the generated nginx.conf and attach here. That'll let us see exactly what config is being used. – Daniel Mikusa Aug 25 '20 at 16:24

0 Answers0