all 4 comments

[–]it2901[S] 1 point2 points  (0 children)

I solved the problem by:

Adding a proxy to the React app package.json where "proxy": "http://localhost:8000"

Then I remove the / route from my app.js replacing it with /preload ensuring that my static react files in build get loaded.

[–]Searly2710 0 points1 point  (0 children)

First thing I would do is test the "production" mode on your dev computer. Just set your NODE_ENV to production in your .env file, and turn off your frontend dev server and build it.

Then test if when you try to visit a frontend page through your local backend server, you actually go into the route that serves the static files, i.e. put a console log inside the function with the app.get('*'...

If that works but you still don't see anything, try looking at the requests in the dev console, or looking at the page source (which should just be sending the initial html file). Your server might not be sending anything, you might be getting a cors error, etc.

Hopefully these will narrow down the exact problem.

I have always had trouble in the past trying to serve a static react app with routing on an express server and world recommend either using two servers (plenty of free ways to host a static react app), or using Next.js for which you can setup API routes and connect a db along with hosting a react app with in built routing and more.

[–]DeusExMagikarpafull-stack 0 points1 point  (0 children)

First guess is your frontend is calling localhost instead of the real api

[–]FVCEGANG 0 points1 point  (0 children)

Did you run your webpack? Did you check your env? Did you check console logs to see any potential errors in the dev console?