forked from forwardemail/forwardemail.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
51 lines (44 loc) · 1.42 KB
/
web.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
// eslint-disable-next-line import/no-unassigned-import
require('./config/env');
const Graceful = require('@ladjs/graceful');
const Mongoose = require('@ladjs/mongoose');
const Redis = require('@ladjs/redis');
const Web = require('@ladjs/web');
const ip = require('ip');
const sharedConfig = require('@ladjs/shared-config');
const config = require('./config');
const logger = require('./helpers/logger');
const webConfig = require('./config/web');
const webSharedConfig = sharedConfig('WEB');
const client = new Redis(webSharedConfig.redis, logger);
const web = new Web(webConfig(client));
if (!module.parent) {
const mongoose = new Mongoose({ ...web.config.mongoose, logger });
const graceful = new Graceful({
mongooses: [mongoose],
servers: [web],
redisClients: [web.client, client],
logger
});
graceful.listen();
(async () => {
try {
await web.listen(web.config.port);
if (process.send) process.send('ready');
const { port } = web.server.address();
logger.info(
`Lad web server listening on ${port} (LAN: ${ip.address()}:${port})`
);
if (config.env === 'development')
logger.info(
`Please visit ${config.urls.web} in your browser for testing`
);
await mongoose.connect();
} catch (err) {
logger.error(err);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
})();
}
module.exports = web;