forked from whxaxes/slither
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
102 lines (82 loc) · 2.08 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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}`;
var l = console.log.bind(console)
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
}
});
server.listen(devport);
var express = require('express')
var app = express();
var http = require('http').Server(app)
var io = require('socket.io')(http)
io.on('connection', function(socket){
// socket.on('report', function(data){
// l(data)
// })
socket.on('born', function(data){
socket.broadcast.emit('born', data);
})
})
app.get('/', function(req, res){
var html = fs.readFileSync('./index.html')
.toString()
.replace(/\.\/dist\//g, `${domain}/static/`)
res.send(html)
})
// http.listen(port)
http.listen(port, function(){
});
// 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);
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;
}