-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 903 Bytes
/
index.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
// Required Third-Party Dependencies
import Addon from "@slimio/addon";
// import { initialize } from "@slimio/modules";
// Require Internal Dependencies
import createServer from "./src/httpServer.js";
import polka from "polka";
// CONSTANTS & Variables
const PORT = process.env.PORT || 1338;
/** @type {polka.Polka} */
let httpServer = null;
const ihm = new Addon("ihm", { verbose: true })
.lockOn("gate")
.lockOn("events");
// initialize(ihm);
// Catch start event!
ihm.on("awake", async() => {
httpServer = createServer(ihm);
httpServer.listen(PORT, () => {
ihm.logger.writeLine(`Server started at: ${`http://localhost:${PORT}`}`);
});
await ihm.ready();
});
// Catch stop event
ihm.on("sleep", () => {
if (httpServer !== null) {
httpServer.server.close();
httpServer = null;
}
});
// Export addon for SlimIO Core.
export default ihm;