blob: 2b1334df0eedfc39edf539176c2e98f3c0b230d4 (
plain)
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
|
import { createServer } from 'http';
import { open } from "fs/promises";
import path from 'path';
import { fileURLToPath } from 'url';
const MIME = {
'.html': 'text/html',
'.js': 'application/javascript',
'.map': 'application/json',
'.hex': 'text/plain',
};
const PORT = 8000;
const ROOT = path.dirname(fileURLToPath(import.meta.url)) + "/dist";
const notFound = (res) => {
res.writeHead(404);
res.end("Not found");
}
const error = (res) => {
res.writeHead(500);
res.end("Internal error");
}
createServer(async (req, res) => {
const urlPath = req.url.split('?')[0];
const file = path.join(ROOT, urlPath === '/' ? '/index.html' : urlPath);
if (!file.startsWith(ROOT + "/")) return notFound(res);
try {
await using fd = await open(file, "r");
res.writeHead(200, {
"Content-Type": MIME[path.extname(file)] ?? "text/plain"
});
for await (const chunk of fd.createReadStream()) {
res.write(chunk);
}
res.end();
} catch (e) {
if (e instanceof Error && e.code === "ENOENT") {
notFound(res);
} else {
console.error(e);
error(res);
}
}
}).listen(PORT, () => console.log(`anduril-sim @ http://localhost:${PORT}`));
|
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation
Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions.
For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage.
In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.