diff --git a/package.json b/package.json index c50461f..82119ee 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ "build": "npm run js:build && npm run css:build", "lint": "eslint assets/**/*.js", "coverage": "nyc npm run test", + "cypress": "$(npm bin)/cypress run", "test": "mocha --require ./config/test.js --compilers js:babel-core/register \"./src/**/**/**/**/*.test.js\"", "test:watch": "npm run test -- --watch --inspect=5556", - "cypress": "$(npm bin)/cypress run", + "test:ci": "concurrently --kill-others --prefix-colors yellow,green \"npm run start\" \"npm run cypress\"", "css:watch": "nodemon -e scss -x \"npm run css:build\"", "css:build": "npm run css:sass -s && npm run css:prefix -s && npm run css:min -s", "css:sass": "node-sass --output-style expanded --include-path scss src/styles/base.scss public/assets/styles/base.css && node-sass --output-style expanded --include-path scss src/styles/choices.scss public/assets/styles/choices.css", diff --git a/server.js b/server.js index 06016a3..643d229 100644 --- a/server.js +++ b/server.js @@ -16,21 +16,35 @@ if (process.env.NODE_ENV !== 'production') { console.log('Compiling bundle... 👷🏽'); const compiler = webpack(config); - app.use(webpackDevMiddleware(compiler, { - publicPath: '/assets/scripts/', - stats: { - colors: true, - }, - })); + app.use( + webpackDevMiddleware(compiler, { + publicPath: '/assets/scripts/', + stats: { + colors: true, + }, + }), + ); app.use(webpackHotMiddleware(compiler)); } app.use(express.static(DIST_DIR)); -app.listen(PORT, (err) => { + +const server = app.listen(PORT, err => { if (err) { console.log(err); } console.log(`Listening at http://localhost:${PORT} 👂`); }); + +process.on('SIGTERM', () => { + if (server) { + server.close(() => { + console.log('Shutting down server'); + process.exit(0); + }); + } else { + process.exit(0); + } +});