forked from whxaxes/slither
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (60 loc) · 1.46 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.base');
const http = require('http');
const fs = require('fs');
const os = require('os');
const ip = getIp();
const port = 9999;
const devport = port - 1;
const domain = `http://${ip}:${devport}`;
const server = new WebpackDevServer(webpack({
devtool: 'eval',
entry: {
main: [
'webpack/hot/only-dev-server',
`webpack-dev-server/client?${domain}`,
config.entry.main
]
},
output: config.output,
plugins: config.plugins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
]),
module: config.module,
resolve: config.resolve,
}), {
publicPath: `${domain}/static/`,
hot: true,
historyApiFallback: true,
port: devport,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
});
http.createServer((req, res) => {
res.writeHead(200, {
'content-type': 'text/html;charset=utf-8'
});
res.end(
fs.readFileSync('./index.html')
.toString()
.replace(/\.\/dist\//g, `${domain}/static/`)
);
}).listen(port);
server.listen(devport);
function getIp() {
'use strict';
const interfaces = os.networkInterfaces();
let IPv4 = '127.0.0.1';
for (let key in interfaces) {
interfaces[key].forEach(function(details) {
if (details.family == 'IPv4' && (key == 'en0' || key == 'eth0')) {
IPv4 = details.address;
}
});
}
return IPv4;
}