init
This commit is contained in:
41
src/routes/docs/main.js
Normal file
41
src/routes/docs/main.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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();
|
||||
|
||||
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>`);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user