-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (61 loc) · 1.82 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
56
57
58
59
60
61
import { createServer } from "node:http";
import { networkInterfaces } from 'os';
import { readFile } from "node:fs/promises";
const PORT = 8080;
// Define a map of files to serve
const files = {
"/TwitchScript.js": {
content: await readFile("TwitchScript.js"),
type: "application/javascript",
},
"/TwitchConfig.json": {
content: await readFile("TwitchConfig.json"),
type: "application/json",
},
"/TwitchIcon.png": {
content: await readFile("TwitchIcon.png"),
type: "image/png",
},
};
function getLocalIPAddress() {
const br = networkInterfaces();
const network_devices = Object.values(br);
if (network_devices !== undefined) {
for (const network_interface of network_devices) {
if (network_interface === undefined) {
continue;
}
for (const { address, family } of network_interface) {
if (family === "IPv4" && address !== "127.0.0.1") {
return address;
}
}
}
}
throw new Error("panic");
}
createServer((req, res) => {
const file = (() => {
switch (req.url) {
case "/TwitchScript.js":
return files[req.url];
case "/TwitchConfig.json":
return files[req.url];
case "/TwitchIcon.png":
return files[req.url];
default:
return undefined;
}
})();
if (file !== undefined) {
res.writeHead(200, { "Content-Type": file.type });
res.end(file.content);
return;
}
res.writeHead(404);
res.end("File not found");
return;
}).listen(PORT, () => {
console.log(`Server running at http://${getLocalIPAddress()}:${PORT}/TwitchConfig.json`);
});
//# sourceMappingURL=server.js.map