Last active
September 24, 2020 14:39
-
-
Save jinwook-k/e8153dedff015b835d0079dba2effabf to your computer and use it in GitHub Desktop.
server/server.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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