feat: local redoc view on development mode only

v1.18.x
Julian Lam 5 years ago
parent c82a263788
commit 1136a369f3

@ -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 nconf = require('nconf');
const fs = require('fs').promises;
const path = require('path');
module.exports = function (app) {
var router = express.Router();
@ -10,5 +13,17 @@ module.exports = function (app) {
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);
};

Loading…
Cancel
Save