-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.js
executable file
·54 lines (44 loc) · 1.18 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
#!/usr/bin/env node
"use strict";
const PORT=8080;
// Webpack build server
var webpack = require('webpack');
var config = require('./webpack.config.js');
var compiler = webpack(config);
var colors = require('colors');
var logSemaphore = 0;
compiler.watch({},function(err,stats) {
console.log(stats.toString({colors:true,chunks:false,children:false}));
logSemaphore++;
setTimeout(function() {
logSemaphore--;
if(logSemaphore == 0) {
console.log();
serverStatus();
console.log();
}
},100);
});
// Express web server
var express = require('express');
var app = express();
var os = require('os');
var ifaces = os.networkInterfaces();
app.use('/dist', express.static(__dirname + '/dist'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(PORT, function() {
serverStatus();
});
function serverStatus() {
console.log("Server listening on:")
console.log(colors.cyan("http://localhost:%s"), PORT);
Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].forEach(function (iface) {
if ('IPv4' === iface.family && iface.internal === false) {
console.log(colors.cyan("http://%s:%s"), iface.address, PORT);
}
});
});
}