-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.ts
46 lines (38 loc) · 1.05 KB
/
app.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
45
46
import bodyParser from "body-parser";
import type { Request, Response } from "express";
//@ts-ignore
import { app, errorHandler } from "mu";
import dispatch from "./config/dispatch";
import { Changeset } from "./types";
import { writeInitialState } from "./writeInitialState";
import { cronjob as autoHealing } from "./self-healing/cron";
import { AUTO_HEALING } from "./config";
app.use(
bodyParser.json({
limit: "500mb",
// @ts-ignore
type: function (req: Request) {
return /^application\/json/.test(req.get("content-type") as string);
},
})
);
app.post("/publish", async function (req: Request, res: Response) {
try {
const changeSets: Changeset[] = req.body;
await dispatch(changeSets);
res.send("Resource added to LDES");
} catch (e) {
console.error(e);
res.status(500).send();
}
});
new Promise(async (resolve) => {
if (process.env.WRITE_INITIAL_STATE === "true") {
await writeInitialState();
}
if (AUTO_HEALING == "true") {
autoHealing.start();
}
resolve(true);
});
app.use(errorHandler);