-
Notifications
You must be signed in to change notification settings - Fork 121
/
web.js
64 lines (56 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright (c) Forward Email LLC
* SPDX-License-Identifier: BUSL-1.1
*/
const process = require('node:process');
// eslint-disable-next-line import/no-unassigned-import
require('#config/env');
// eslint-disable-next-line import/no-unassigned-import
require('#config/mongoose');
const Graceful = require('@ladjs/graceful');
const Redis = require('@ladjs/redis');
const Web = require('@ladjs/web');
const ip = require('ip');
const mongoose = require('mongoose');
const sharedConfig = require('@ladjs/shared-config');
const Users = require('#models/users');
const config = require('#config');
const logger = require('#helpers/logger');
const monitorServer = require('#helpers/monitor-server');
const setupMongoose = require('#helpers/setup-mongoose');
const webConfig = require('#config/web');
const webSharedConfig = sharedConfig('WEB');
const redis = new Redis(
webSharedConfig.redis,
logger,
webSharedConfig.redisMonitor
);
const web = new Web(webConfig(redis), Users);
const graceful = new Graceful({
mongooses: [mongoose],
servers: [web.server],
redisClients: [redis],
logger
});
graceful.listen();
monitorServer();
(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})`,
{ hide_meta: true }
);
if (config.env === 'development')
logger.info(
`Please visit ${config.urls.web} in your browser for testing`,
{ hide_meta: true }
);
await setupMongoose(logger);
} catch (err) {
await logger.error(err);
process.exit(1);
}
})();