-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (35 loc) · 1.05 KB
/
Copy pathserver.js
File metadata and controls
43 lines (35 loc) · 1.05 KB
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
import express from "express";
import handler from "./api/yiff.js";
const app = express();
const port = Number(process.env.PORT) || 3000;
// Render uses this endpoint to verify that the service is running.
app.get("/healthz", (_req, res) => {
res.status(200).json({ status: "ok" });
});
// Express equivalents of the rewrites previously defined in vercel.json.
app.all("/posts/:postId/file.:ext", (req, res) => {
req.e694Query = {
...req.query,
slug: `${req.params.postId}.${req.params.ext}`,
};
return handler(req, res);
});
app.all("/posts/:postId/file", (req, res) => {
req.e694Query = { ...req.query, slug: req.params.postId };
return handler(req, res);
});
app.all("/posts/:postId", (req, res) => {
req.e694Query = {
...req.query,
slug: req.params.postId,
embed: "true",
};
return handler(req, res);
});
app.use(express.static("public"));
app.use((_req, res) => {
res.status(404).sendFile("404.html", { root: "public" });
});
app.listen(port, "0.0.0.0", () => {
console.log(`e694 is listening on port ${port}`);
});