forked from onilabs/conductance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_config.mho
86 lines (76 loc) · 2.09 KB
/
default_config.mho
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
81
82
83
84
85
86
// Default conductance configuration
@ = require('mho:std');
var server = require('mho:server');
//----------------------------------------------------------------------
// function invoked by `conductance serve`
exports.serve = function(args) {
var parser = require('sjs:dashdash').createParser({
options: [
{
name: 'cors',
type: 'bool',
help: 'enable CORS',
'default': false,
},
{
names: ['help', 'h'],
type: 'bool',
},
{
names: ['host'],
type: 'string',
help: 'serve on address (default: "localhost". Use "any" to serve on any address")',
'default': 'localhost',
},
{
names: ['port'],
type: 'number',
help: 'serve on port (default: 7075)',
'default': 7075,
},
{
names: ['ssl'],
type: 'bool',
help: 'serve over https (NOTE: uses the default conductance certificate, use for testing only)',
'default': false,
},
]
});
try {
var opts = parser.parse(args);
} catch(e) {
console.error('Error: ', e.message);
process.exit(1);
}
if (opts.help) {
console.log(" default_config.mho options:\n");
console.log(parser.help({includeEnv:true}));
process.exit(0);
}
var routes = [
@route.ExecutableDirectory('__mho/doc', @env.conductanceRoot + '/doc'),
@route.SystemRoutes(),
@route.ExecutableDirectory(process.cwd()),
] .. @route.LogRequests(@logging.INFO);
if (process.env.NODE_ENV !== 'production') {
// show stacktraces
routes = routes .. @route.DeveloperMode();
}
var host = opts.host == 'any' ? null : opts.host;
var port = opts.port;
var ssl = opts.ssl;
var address = @Port(port, host);
if (opts.ssl) {
address = address.ssl({
key: @fs.readFile("#{@env.conductanceRoot}ssl/insecure-localhost.key"),
cert: @fs.readFile("#{@env.conductanceRoot}ssl/insecure-localhost.crt")
});
}
if (opts.cors) {
routes = routes .. @route.AllowCORS;
};
@server.run({
address: address,
routes: routes,
});
};