79245546

Date: 2024-12-02 20:51:10
Score: 0.5
Natty:
Report link

The issue is that try files is being executed always so all the requests no matter the path used end up returning index.html. To fix it I followed a suggestion from Matt Holt in this forum. By using router and switching the reverse proxy to be the first line, the backend starts being called before.

# Main site for biospringbok.com
biospringbok.com {
        root * /var/www/html # Path to your React app's build folder


        #Route is used to ensure that first reverse proxy is executed and only resort to try files if its not an api call
        route {
                reverse_proxy /api/* localhost:8080

                # Redirect all routes not matching files to index.html for client-side routing
                try_files {path} /index.html # This allows React Router to take over for non-file URLs

                # Serve static files (React app)
                file_server
           }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Tomaz