-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.mjs
32 lines (26 loc) · 872 Bytes
/
index.mjs
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
#!/bin/env node
import express from "express";
import cors from "cors";
import mergeFiles from "./modules/merger.mjs";
const app = express();
const PORT = process.env.PORT || 3500;
app.use(cors());
app.use(express.json({ limit: "50mb" }));
app.use(express.static("public"));
app.listen(PORT, () => console.log(`Listening on: http://localhost:${PORT}`));
app.post("/api/merge", (req, res) => {
const result = mergeFiles(req.body);
if (result.ok) {
const file = result.value;
res.setHeader("Content-Length", file.length);
res.setHeader("Content-Type", "application/x-xopp");
res.setHeader(
"Content-Disposition",
`attachment; filename=${req.body.output}`
);
res.end(file);
} else {
console.error(result.error);
res.status(400).json({ error: result.error });
}
});