-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
27 lines (24 loc) · 1.01 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import http from 'http';
import express from 'express';
import bodyParser from 'body-parser';
import morgan from 'morgan';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from './webpack/common.config';
const app = express();
const port = process.env.PORT || 3000;
const compiler = webpack(webpackConfig);
app.use(morgan('short'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
app.use(webpackHotMiddleware(compiler, { log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000 }));
app.use(express.static(`${__dirname}/public`));
app.get('/', function(req, res) {
res.sendFile(`${__dirname}/public/index.html`);
});
const server = http.createServer(app);
server.listen(port, function() {
console.log('Listening on: https://localhost:%d', server.address().port);
});