Created
February 21, 2018 09:32
-
-
Save laugri/4ddb164b4fe8d9549c4a2dd6a9cd3dfd to your computer and use it in GitHub Desktop.
This file contains 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
const express = require('express'); | |
const morgan = require('morgan'); | |
const path = require('path'); | |
const PORT = process.env.PORT || 3000; | |
const app = express(); | |
const logger = morgan( | |
process.env.NODE_ENV !== 'production' ? 'dev' : 'combined', | |
); | |
app.use(logger); | |
app.use(express.static('build', { index: 'index.html' })); | |
app.get('*', (req, res) => { | |
res.sendFile(path.join(__dirname, 'build', 'index.html')); | |
}); | |
app.listen(PORT, err => { | |
if (err) { | |
// eslint-disable-next-line no-console | |
console.log(`server failed to listen on port ${PORT}: ${err.code}`); | |
} else { | |
// eslint-disable-next-line no-console | |
console.log(`server listening on port ${PORT}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment