2025-01-13 23:18:10 +02:00
|
|
|
import type { Router } from "express";
|
2024-04-07 18:18:26 +03:00
|
|
|
|
2024-07-18 21:37:45 +03:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
2025-04-25 13:26:08 +03:00
|
|
|
import { RESOURCE_DIR } from "../services/resource_dir";
|
2022-01-07 23:06:04 +01:00
|
|
|
|
2025-04-25 13:26:08 +03:00
|
|
|
const specPath = path.join(RESOURCE_DIR, "etapi.openapi.yaml");
|
2024-04-16 21:10:39 +03:00
|
|
|
let spec: string | null = null;
|
2022-01-07 23:06:04 +01:00
|
|
|
|
2024-04-07 18:18:26 +03:00
|
|
|
function register(router: Router) {
|
2025-04-25 13:26:08 +03:00
|
|
|
router.get("/etapi/etapi.openapi.yaml", (_, res) => {
|
2022-01-07 23:06:04 +01:00
|
|
|
if (!spec) {
|
2025-01-09 18:07:02 +02:00
|
|
|
spec = fs.readFileSync(specPath, "utf8");
|
2022-01-07 23:06:04 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
res.header("Content-Type", "text/plain"); // so that it displays in browser
|
2022-01-07 23:06:04 +01:00
|
|
|
res.status(200).send(spec);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2022-01-07 23:06:04 +01:00
|
|
|
register
|
|
|
|
};
|