-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
55 lines (46 loc) · 1.36 KB
/
server.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
import { buildApp } from "./app.js";
import config from "./config.js";
const startServer = async () => {
try {
const server = await buildApp({
logger: true,
forceCloseConnections: true,
});
await server.listen({
port: config.AUTHPORT,
host: "0.0.0.0",
});
const addresses = server.addresses();
printStartupMessage(addresses[0].address, addresses[0].port);
setupGracefulShutdown(server);
} catch (err) {
console.error(err);
process.exit(1);
}
};
function printStartupMessage(address, port) {
console.log(`
###########################################################
The AuthCompanion Server has started
🖥️ Client UI on: http://localhost:${port}/v1/web/login
🚀 Admin UI on: http://localhost:${port}/v1/admin/login
###########################################################
`);
console.log("Use CTRL-C to shut down AuthCompanion");
}
function setupGracefulShutdown(server) {
const handleSignal = async () => {
try {
await server.close();
server.log.info(`AuthCompanion has exited. Goodbye! 👋`);
process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
};
process.on("SIGTERM", handleSignal);
process.on("SIGINT", handleSignal);
process.on("SIGUSR2", handleSignal);
}
startServer();