The naïve wayQuick and simple - clone your project, start the server and client services, and point nginx at your client app, same as you did during development. The "proxy" config in the client app then redirects requests to the backend server.
Does this seem right? I don't think so...
The express wayAll the documentation I initially read suggests to do this using Express. Modify your Express configuration (for your back-end) so that it serves up the compiled React app from client/build
You'll then point nginx at your
It's a better idea - now at least you only have one express server runnning... but it still doesn't feel quite right. The whole point of your initial setup was that you could separate client and server, but now your server app has to be changed so that it can host the client too?
This can be done as follows with a simple nginx configuation:
Here, we tell nginx to serve files on port 80 with the particular servername from the build directory of my deployed application.
Using the magic of try_files, anything that isn't found is instead fetched from the node_backend - here assumed to be running on the same server, on port 5000.
Simple, efficient, and no changes to code needed!