-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ts
32 lines (26 loc) · 897 Bytes
/
index.ts
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
import * as dotenv from 'dotenv';
dotenv.config();
import { buildContext } from './context.js';
import { buildServer } from './server/server.js';
import { buildPlugins } from './server/plugins.js';
const PORT = process.env.PORT || 8080;
(async function main() {
try {
const context = await buildContext(process.env.PG_CONN);
const plugins = await buildPlugins();
const server = buildServer(context, plugins);
server.listen(PORT, () => {
console.info(`Server is running on port: ${PORT}`);
});
['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => {
process.on(signal, () => server.close());
});
server.on('close', async () => {
await context.db_client.close();
process.exit(0); // normal termination
});
} catch (error) {
console.error('An error occurred:', error);
process.exit(1); // exit with an error code
}
})();