-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
46 lines (44 loc) · 1.23 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import path from 'path';
import express from 'express';
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import config from './webpack.config.js';
import ip from 'ip';
import colors from 'colors';
const port = '3008'
const app = express();
const compiler = webpack(config);
const middleware = webpackMiddleware(compiler, {
contentBase: 'dist/',
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
}
});
app.use(middleware);
app.use(webpackHotMiddleware(compiler));
//app.use('/', routes);
app.get('*', function response(req, res) {
//if no favicon
if (req.url === '/favicon.ico') {
res.writeHead(200, {'Content-Type': 'images/x-icon'});
res.end();
return;
}
if (req.url.indexOf('service')>=0){
return;
}
res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'build/index.html')));
res.end();
});
app.listen(port, ip.address(), function onStart(err) {
if (err) {
console.log(err);
}
console.info('==> 🌎 Listening on ' + (ip.address() + ':3008').blue);
});