-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·78 lines (71 loc) · 2.64 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
#!/usr/bin/env node
var program = require('commander');
program
.version(require('./package.json').version)
.option('-H --listen-http [port:host]', 'HTTP listening address', 1522)
.option('-S --listen-https [port:host]', 'HTTPS listening address', 1523)
.option('-C --pem-prefix [path prefix of pem file]', 'SSL (C)ert prefix, {key: @-key.pem, cert: @-cert.pem} for https server')
.option('-P --listen-path [filepath]', 'unix-domain-socket/windows-named-pipe path')
.option('-r --raw-http [port:host]', 'raw HTTP listening address', '1530')
.option('-s --raw-scgi [port:host]', 'raw SCGI listening address', '1531')
.option('-f --raw-fcgi [port:host]', 'raw FCGI listening address', '1532')
.option('-c, --client_config [file]', 'client control configuration file path')
.option('-k, --keep_alive_interval [seconds]', 'keep_alive_interval', parseInt)
.option('-a, --auth_checker_path [file(js function or json static config)]', 'authentication func or config')
.parse(process.argv)
;
global.args = program;
global.startCfg = {
client_config : program.client_config,
auth_checker_path : program.auth_checker_path,
keep_alive_interval : program.keep_alive_interval || 280,
db : {
name : program.db_name,
domain : program.db_domain,
unique : program.db_unique_name,
inst : program.db_instance,
role : program.db_role,
cfg_id : program.db_cfg_id
}
};
(function initConfig(cfg){
console.log(cfg);
if (cfg.client_config) {
client_cfgs = require(cfg.client_config);
global.gConfig = client_cfgs;
if (client_cfgs.client_config) {
client_cfgs = client_cfgs.client_config;
}
} else {
client_cfgs = {
demo : {
min_concurrency : 3,
max_concurrency : 3,
passwd : 'demo'
}
};
}
global.client_cfgs = client_cfgs;
global.keepAliveInterval = cfg.keep_alive_interval;
var authModule, authChecker;
if (cfg.auth_checker_path) {
switch (cfg.auth_checker_path[0]) {
case '/' :
authModule = require(cfg.auth_checker_path);break;
case '.':
authModule = require(cfg.auth_checker_path);break;
default:
authModule = require(require('path').join('./', cfg.auth_checker_path));
}
if (authModule && typeof authModule === 'function') {
global.authChecker = authModule.check(cfg);
} else {
// use static configuration json file for checker rule
global.authChecker = require('./check_by_config.js')(authModule);
}
} else {
// checker that allow intranet ip, forbid internet ip, it's for default
global.authChecker = require('./check_intra_inter.js')(cfg);
}
})(startCfg);
require('./handshake.js');