-
Notifications
You must be signed in to change notification settings - Fork 117
/
api.js
49 lines (42 loc) · 1.24 KB
/
api.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
/**
* 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 API = require('@ladjs/api');
const Graceful = require('@ladjs/graceful');
const mongoose = require('mongoose');
const ip = require('ip');
const apiConfig = require('#config/api');
const Users = require('#models/users');
const logger = require('#helpers/logger');
const setupMongoose = require('#helpers/setup-mongoose');
const monitorServer = require('#helpers/monitor-server');
const api = new API(apiConfig, Users);
const graceful = new Graceful({
mongooses: [mongoose],
servers: [api.server],
redisClients: [api.client],
logger
});
graceful.listen();
monitorServer();
(async () => {
try {
await api.listen(api.config.port);
if (process.send) process.send('ready');
const { port } = api.server.address();
logger.info(
`Lad API server listening on ${port} (LAN: ${ip.address()}:${port})`,
{ hide_meta: true }
);
await setupMongoose(logger);
} catch (err) {
await logger.error(err);
process.exit(1);
}
})();