2018-05-27 12:57:21 +02:00
|
|
|
/* eslint-disable no-console,global-require,import/no-extraneous-dependencies */
|
2018-05-25 15:00:27 +02:00
|
|
|
const express = require('express');
|
|
|
|
const path = require('path');
|
2016-03-15 23:42:10 +01:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
const PORT = 3001;
|
|
|
|
const DIST_DIR = path.join(__dirname, 'public');
|
2018-05-25 15:00:27 +02:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
const app = express();
|
2018-05-27 12:57:21 +02:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2018-05-27 12:57:21 +02:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
|
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
|
|
const config = require('./webpack.config.dev');
|
|
|
|
|
|
|
|
console.log('Compiling bundle... 👷🏽');
|
|
|
|
const compiler = webpack(config);
|
|
|
|
|
2018-10-10 13:44:08 +02:00
|
|
|
app.use(
|
|
|
|
webpackDevMiddleware(compiler, {
|
|
|
|
publicPath: '/assets/scripts/',
|
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2018-05-27 12:57:21 +02:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
app.use(webpackHotMiddleware(compiler));
|
2018-05-27 12:57:21 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
app.use(express.static(DIST_DIR));
|
2018-10-10 13:44:08 +02:00
|
|
|
|
|
|
|
const server = app.listen(PORT, err => {
|
2018-05-25 17:51:21 +02:00
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
2018-05-27 12:57:21 +02:00
|
|
|
|
2018-05-27 18:13:29 +02:00
|
|
|
console.log(`Listening at http://localhost:${PORT} 👂`);
|
2018-05-25 17:51:21 +02:00
|
|
|
});
|
2018-10-10 13:44:08 +02:00
|
|
|
|
|
|
|
process.on('SIGTERM', () => {
|
|
|
|
if (server) {
|
|
|
|
server.close(() => {
|
|
|
|
console.log('Shutting down server');
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|