-
Notifications
You must be signed in to change notification settings - Fork 33
/
server.js
50 lines (37 loc) · 970 Bytes
/
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
var connect = require('connect'),
colors = require('colors'),
argv = require('optimist').argv,
portfinder = require('portfinder'),
modRewrite = require('connect-modrewrite');
var port = argv.p,
logger = argv.l,
log = console.log;
if (!argv.p) {
portfinder.basePort = 8080;
portfinder.getPort(function (err, port) {
if (err) throw err;
listen(port);
});
} else {
listen(port);
}
function listen(port) {
var server = connect();
server
.use(modRewrite([
'^/(([^\/]*).xhtml|([0-9]+)/(.+))$ /src/index.html [L]',
'^(.*)$ /src/$1 [L]'
]))
.use(connect.static(__dirname))
if(!logger) server.use(connect.logger(logger))
server.listen(port);
log('Starting up Server, serving '.yellow
+ __dirname.green
+ ' on port: '.yellow
+ port.toString().cyan);
log('Hit CTRL-C to stop the server');
}
process.on('SIGINT', function () {
log('http-server stopped.'.red);
process.exit();
});