mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: local redoc view on development mode only
This commit is contained in:
24
public/vendor/redoc/index.html
vendored
Normal file
24
public/vendor/redoc/index.html
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>ReDoc</title>
|
||||||
|
<!-- needed for adaptive design -->
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
ReDoc doesn't change outer page styles
|
||||||
|
-->
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<redoc spec-url="apiUrl"></redoc>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
|
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
@@ -10,5 +13,17 @@ module.exports = function (app) {
|
|||||||
res.redirect(404);
|
res.redirect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Redoc
|
||||||
|
router.get('/spec/read', async (req, res) => {
|
||||||
|
const handle = await fs.open(path.resolve(__dirname, '../../public/vendor/redoc/index.html'), 'r');
|
||||||
|
let html = await handle.readFile({
|
||||||
|
encoding: 'utf-8',
|
||||||
|
});
|
||||||
|
await handle.close();
|
||||||
|
|
||||||
|
html = html.replace('apiUrl', nconf.get('relative_path') + '/assets/openapi/read.yaml');
|
||||||
|
res.status(200).type('text/html').send(html);
|
||||||
|
});
|
||||||
|
|
||||||
app.use(nconf.get('relative_path') + '/debug', router);
|
app.use(nconf.get('relative_path') + '/debug', router);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user