-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
39 lines (31 loc) · 894 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
// Import Node.js Dependencies
import { fileURLToPath } from "node:url";
import path from "node:path";
import fs from "node:fs";
// Import Third-party Dependencies
import polka from "polka";
import send from "@polka/send";
import sirv from "sirv";
// Import Internal Dependencies
import * as orgCache from "./src/cache.js";
import WSS from "./src/WebSocket.class.js";
// CONSTANTS
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const kHttpPort = process.env.PORT || 1337;
fs.mkdirSync(orgCache.CACHE_PATH, {
recursive: true
});
const httpServer = polka();
new WSS({ port: 1338 });
httpServer.use(
sirv(path.join(__dirname, "public"), { dev: true })
);
httpServer.get("/health", (req, res) => {
send(res, 200, {
uptime: process.uptime()
});
});
httpServer.listen(
kHttpPort,
() => console.log(`HTTP Server listening on http://localhost:${kHttpPort}`)
);