forked from bmayton/node-emberplus
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserve.js
executable file
·58 lines (51 loc) · 1.25 KB
/
serve.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
const yargs = require('yargs');
const { EmberServer, Decoder } = require('./index');
const { readFileSync } = require('fs');
const argv = yargs.options({
host: {
alias: 'h',
description: 'host name|ip',
default: '0.0.0.0'
},
port: {
alias: 'p',
default: 9000,
type: 'number',
description: 'port',
demandOption: true
},
file: {
alias: 'f',
description: 'file containing the ber (default) or json tree',
demandOption: true
},
json: {
alias: 'j',
type: 'boolean',
description: 'file format is json'
},
debug: {
alias: 'd',
type: 'boolean',
description: 'debug'
}
}).help().argv;
const main = async () => {
const data = readFileSync(argv.file);
const tree = argv.json ? EmberServer.JSONtoTree(JSON.parse(data.toString())) : Decoder(data);
const server = new EmberServer(argv.host, argv.port, tree);
server.on('error', (e) => {
console.log(e);
});
server._debug = true;
console.log(Date.now(), 'starting server');
if (argv.debug) {
server._debug = true;
}
try {
server.listen();
} catch (e) {
console.log(e);
}
};
main();