Skip to content

Instantly share code, notes, and snippets.

@jinwook-k
Last active September 24, 2020 14:39
Show Gist options
  • Save jinwook-k/e8153dedff015b835d0079dba2effabf to your computer and use it in GitHub Desktop.
Save jinwook-k/e8153dedff015b835d0079dba2effabf to your computer and use it in GitHub Desktop.
server/server.js
// imports
const path = require('path');
// use body parser to get data from POST requests
// Use API routes from the api folder
// If in production, then use static frontend build files.
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, '../client/build')));
// Handle React routing, return all requests to React app
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));
});
}
// Connect to Mongo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment