@apolitical/server
Version:
Node.js module to encapsulate Apolitical's express server setup
21 lines (18 loc) • 592 B
JavaScript
;
module.exports = ({
httpStatusCodes: { MOVED_PERMANENTLY },
config,
swaggerUi: { serve, setup },
authorisationMiddleware,
}) => {
const { DOCUMENTATION } = config.ENDPOINTS;
return function load(app, { swaggerDocument }) {
// Load document endpoint
if (swaggerDocument) {
// Redirection to documentation
app.use(`${DOCUMENTATION}index.html`, (req, res) => res.redirect(MOVED_PERMANENTLY, DOCUMENTATION));
// Documentation express setup
app.use(DOCUMENTATION, authorisationMiddleware(), serve, setup(swaggerDocument));
}
};
};