-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (39 loc) · 1.27 KB
/
index.ts
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
import * as http from "node:http";
import process from "node:process";
import { ping } from "./src/operation/ping.ts";
import { version } from "./src/operation/version.ts";
import { generate, generateFromZip } from "./src/generate.ts";
import { convertMathMLToLatex } from "./src/mathml.ts";
import { deleteFolderOlderThan } from "./src/fs.ts";
const server = http.createServer(
async (
req: http.IncomingMessage,
res: http.ServerResponse<http.IncomingMessage>
) => {
const parts = (req.url || "").split("?");
const path = parts.length > 0 ? parts[0] : "";
//console.log(req.url);
switch (path) {
case "/ping":
return ping(req, res);
case "/version":
return version(req, res);
case "/pdf":
await houseKeeping();
return generate(req, res);
case "/zip":
await houseKeeping();
return generateFromZip(req, res);
case "/mathml":
return await convertMathMLToLatex(req, res);
default:
return version(req, res);
}
}
);
server.listen(process.env.PORT || 5050);
console.log(`arc-latex-be v. 1.0.0 started.`);
const houseKeeping = async (): Promise<void> => {
const historyDays = +(process.env?.LOG_HISTORY_DAYS || 60);
await deleteFolderOlderThan(historyDays, "/tmp");
};