-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
executable file
·72 lines (59 loc) · 1.75 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
#!/usr/bin/env node
'use strict';
const yargs = require('yargs');
const assert = require('assert');
const config = require('config');
const argv = yargs
.wrap(Math.min(120, yargs.terminalWidth()))
.version()
.alias('version', 'v')
.help('help')
.alias('help', 'h')
.command('[options]')
.usage('Usage: $0 [options]\n\nStarts the badges server.')
.option('hostname', {
type: 'string',
default: config.get('listen.hostname'),
alias: 'H',
describe: 'Specify the hostname',
})
.option('port', {
type: 'number',
default: config.get('listen.port'),
alias: 'p',
describe: 'Specify the port',
})
.option('backlog', {
type: 'number',
default: config.get('listen.backlog'),
alias: 'b',
describe: 'Specify the backlog size',
})
.option('log-level', {
type: 'string',
default: 'warn',
alias: 'll',
describe: 'The log level to use',
choices: ['fatal', 'error', 'warn', 'info', 'debug', 'trace'],
})
.check((argv) => {
assert(argv.port >= 0, 'Invalid argument: --port must be a number greater than or equal to 0');
assert(argv.backlog >= 0, 'Invalid argument: --backlog must be a number greater than or equal to 0');
return true;
})
.argv;
// ------------------------------------------------------------
require('./lib/configure');
logger.level = argv.logLevel;
const elasticsearch = require('elasticsearch');
const app = require('./');
const esClient = new elasticsearch.Client(config.get('elasticsearch'));
const log = logger.child({ module: 'server' });
app(config.get('app'), esClient)
.listen(argv.port, argv.hostname, argv.backlog, (err) => {
if (err) {
log.error({ err }, 'Unable to start server');
throw err;
}
log.info(`Now listening on ${argv.hostname}:${argv.port}..`);
});