Notes/src/etapi/spec.ts

23 lines
534 B
TypeScript
Raw Normal View History

2024-04-07 18:18:26 +03:00
import { Router } from "express";
import fs = require('fs');
import path = require('path');
2022-01-07 23:06:04 +01:00
2022-01-08 19:30:46 +01:00
const specPath = path.join(__dirname, '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) {
2022-01-08 19:30:46 +01:00
router.get('/etapi/etapi.openapi.yaml', (req, res, next) => {
2022-01-07 23:06:04 +01:00
if (!spec) {
spec = fs.readFileSync(specPath, 'utf8');
}
res.header('Content-Type', 'text/plain'); // so that it displays in browser
res.status(200).send(spec);
});
}
2024-04-07 18:18:26 +03:00
export = {
2022-01-07 23:06:04 +01:00
register
};