added swagger

This commit is contained in:
Maximilian Baum
2026-04-02 09:36:29 +02:00
parent 8ac8643e6d
commit 88ef8136f3
6 changed files with 1509 additions and 391 deletions

View File

@@ -1,41 +1,9 @@
const express = require('express');
const showdown = require('showdown');
const fs = require('fs');
const path = require('path');
const converter = new showdown.Converter({
tables: true, // Tabellen-Unterstützung aktivieren
ghCompatibleHeaderId: true,
simpleLineBreaks: true,
emoji: true
});
const router = express.Router();
const swaggerUi = require('swagger-ui-express');
const openAPI = require('./openapi.json');
router.get('/', (req, res) => {
const filePath = path.join(__dirname, '../../../doc/api.md');
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
console.error(err);
return res.status(500).send("Fehler beim Laden der Markdown-Datei");
}
const htmlContent = converter.makeHtml(data);
res.set('Content-Type', 'text/html; charset=utf-8');
res.send(`<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>API-Dokumentation</title>
<link rel="stylesheet" href="/css/markdown-dark.css">
</head>
<body>
<main class="markdown-body">
${htmlContent}
</main>
</body>
</html>`);
});
});
router.use('/', swaggerUi.serve);
router.get('/', swaggerUi.setup(openAPI));
module.exports = router;