Skip to content

Instantly share code, notes, and snippets.

@laugri
Created February 21, 2018 09:32
Show Gist options
  • Save laugri/4ddb164b4fe8d9549c4a2dd6a9cd3dfd to your computer and use it in GitHub Desktop.
Save laugri/4ddb164b4fe8d9549c4a2dd6a9cd3dfd to your computer and use it in GitHub Desktop.
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