-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
main.js
60 lines (56 loc) · 1.61 KB
/
main.js
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
50
51
52
53
54
55
56
57
58
59
60
import { handler } from "./build/handler.js";
import { apiReference } from "@scalar/express-api-reference";
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import sitemap from "./sitemap.js";
import fs from "fs-extra";
const PORT = process.env.PORT || 3000;
const app = express();
app.use((req, res, next) => {
if (req.path.startsWith("/embed")) {
res.setHeader("Content-Security-Policy", "frame-ancestors *");
}
res.setHeader("X-Powered-By", "Kener");
next();
});
app.get("/healthcheck", (req, res) => {
res.end("ok");
});
try {
const openapiJSON = fs.readFileSync("./openapi.json", "utf-8");
app.use(
"/api-reference",
apiReference({
spec: {
content: openapiJSON
},
theme: "alternate",
hideModels: true,
hideTestRequestButton: true,
darkMode: true,
metaData: {
title: "Kener API Reference",
description: "Kener free open source status page API Reference",
ogDescription: "Kener free open source status page API Reference",
ogTitle: "Kener API Reference",
ogImage: "https://kener.ing/newbg.png",
twitterCard: "summary_large_image",
twitterTitle: "Kener API Reference",
twitterDescription: "Kener free open source status page API Reference",
twitterImage: "https://kener.ing/newbg.png"
},
favicon: "https://kener.ing/logo96.png"
})
);
} catch (e) {
console.warn("Error loading openapi.json, but that is okay.");
}
app.get("/sitemap.xml", (req, res) => {
res.setHeader("Content-Type", "application/xml");
res.end(sitemap);
});
app.use(handler);
app.listen(PORT, () => {
console.log("Kener is running on port " + PORT + "!");
});