I made it work using express. There may be some gaps in this, so if anyone tries it, feel free to fill in the gaps in the comments and I'll update...
I have both express and react running in two different consoles locally. For some reason, I only needed to run node on the express file in prod. Do whatever you need to to get it running. This will forward the request to the react server.
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
Then I have a route for the pages that I share that looks something like this.
app.get('/details/:itemId', function(req, res) {
const fileName = path.join(__dirname, 'build', `${req.params.itemId}.html`);
var fileContents = fs.readFileSync(path.join(__dirname, 'build', 'index.html'), 'utf8');
fileContents = fileContents.replace("og tags", "new values");
fs.writeFileSync(fileName, fileContents);
res.sendFile(fileName);
});
You probably will want to search for the file and serve that up first if it exists so you aren't having problems with multiple clients writing to the same file at the same time in a high volume environment. Or better yet, do it in memory. Remember, order counts in express, so you really need to reverse the order of these two functions in your express file.