forked from Mailtrain-org/mailtrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (47 loc) · 1.42 KB
/
index.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
'use strict';
/**
* Module dependencies.
*/
let config = require('config');
let log = require('npmlog');
let app = require('./app');
let http = require('http');
let port = config.www.port;
log.level = config.log.level;
app.set('port', port);
/**
* Create HTTP server.
*/
let server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', err => {
if (err.syscall !== 'listen') {
throw err;
}
let bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
// handle specific listen errors with friendly messages
switch (err.code) {
case 'EACCES':
log.error('Express', '%s requires elevated privileges', bind);
process.exit(1);
break;
case 'EADDRINUSE':
log.error('Express', '%s is already in use', bind);
process.exit(1);
break;
default:
throw err;
}
});
server.on('listening', () => {
let addr = server.address();
let bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
log.info('Express', 'WWW server listening on %s', bind);
// start sending loop
require('./services/sender'); // eslint-disable-line global-require
require('./services/importer'); // eslint-disable-line global-require
require('./services/testserver'); // eslint-disable-line global-require
});