forked from garris/BackstopJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (44 loc) · 1.55 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
var express = require('express'),
app = express(),
_ = require('underscore'),
os = require('os'),
sys = require('sys'),
exec = require('child_process').exec,
argv = require('yargs').argv;
var autoShutDownMs = (Number(argv.t) === argv.t && argv.t % 1 === 0) ? 1000 * 60 * argv.t : 1000 * 60 * 15;
var rootDir = __dirname;
var port = argv.p || 3001;
app.use(express.json());
app.use(express.urlencoded());
app.use(express.static(rootDir));
// app.all('/app/',function(req,res){
// console.log(new Date());
// exec("gulp test",puts);
// res.send('ok');
// })
var listenerHook = app.listen(port);
//===================
console.log();
console.log('Current Directory: '+__dirname);
console.log('Serving files from: '+rootDir);
console.log('Listening on: ' + getAddresses() + ':' + port + '');
console.log('Press Ctrl + C to stop.');
if(autoShutDownMs>0){
setTimeout(function(){
console.log('\n['+new Date()+'] Server is shutting down now. Bye!\n');
listenerHook.close();
}, autoShutDownMs);
console.log('\n['+new Date()+'] PLEASE NOTE: THIS SERVER WILL AUTOMATICALLY SHUT DOWN IN ' + Math.round(autoShutDownMs/60000 * 100) / 100+ ' MINS.\n')
}
//=====================
function getAddresses(){
var interfaces = os.networkInterfaces(),
addresses = [];
_.each(interfaces,function(net) {
_.each(net,function(address) {
if (address.family == 'IPv4' && !address.internal) addresses.push(address.address);
});
});
return addresses;
}
function puts(error, stdout, stderr) {sys.puts(stdout)}