-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpushstate-https-server
More file actions
executable file
·81 lines (68 loc) · 1.95 KB
/
pushstate-https-server
File metadata and controls
executable file
·81 lines (68 loc) · 1.95 KB
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
#!/usr/bin/env node
'use strict';
var pushstateServer = require('../lib/pushstate-https-server'),
_ = require('lodash'),
argv = require('minimist')(process.argv.slice(2));
let noArgs = _.isEmpty(argv._) && _.size(_.keys(argv)) == 1;
if (argv.h || argv.help || noArgs) {
console.log([
'usage: pushstate-https-server [options]',
'',
'options:',
' -r Root Directory',
' -a Address to bind [127.0.0.1]',
' -p Port to use [8080]',
' -d Directories with static files, comma separated',
' -s Enable HTTPS',
' -c --cert Path to ssl cert file',
' -k --key Path to ssl private key file',
' -h --help Print this list and exit.'
].join('\n'));
process.exit();
}
var root = argv.r,
address = argv.a || '127.0.0.1',
port = argv.p || 8080,
dirs = _.isEmpty(argv.d) ? [] : _.split(argv.d, ','),
enableSSL = argv.s,
certPath = argv.c,
keyPath = argv.k;
if (!root) {
console.log('Root directory missing. Use -h for more info.');
process.exit();
}
if (enableSSL) {
if (!certPath) {
console.log('HTTPS is enabled but certificate path is missing. Use -h for more info.');
process.exit();
}
if (!keyPath) {
console.log('HTTPS is enabled but private key path is missing. Use -h for more info.');
process.exit();
}
}
let options = {};
options.root = root;
options.address = address;
options.port = port;
options.dirs = dirs;
options.https = enableSSL;
options.certPath = certPath;
options.keyPath = keyPath;
let started = function() {
console.log((options.https ? 'HTTPS' : 'HTTP') + ' pushstate-server started on port ' + options.port + '...');
console.log('Directories with static files: ', options.dirs);
};
let stopped = function() {
console.log('pushstate-server stopped.');
process.exit();
};
process.on('SIGINT', stopped);
process.on('SIGTERM', stopped);
try {
let server = pushstateServer.createServer(options);
server.start(started);
}
catch (e) {
console.log('Exception', e);
}