Disabling swagger-ui in Production #58
-
First of all, thank you so much @hagopj13 for this excellent boilerplate! It makes it much easier and faster to build APIs using Express, especially for those of us with not so much experience. Another reason I love this is that it is well documented and the code well structured. I have a question concerning how one would best disable swagger-ui during production, in this particular boilerplate. I had a look at this Stackoverflow post and the general idea is to return a 404 status if My initial quick and dirty solution is to edit the const express = require('express');
const authRoute = require('./auth.route');
const userRoute = require('./user.route');
const config = require('../../config/config');
const docsRoute = require('./docs.route');
const router = express.Router();
const defaultRoutes = [
{
path: '/auth',
route: authRoute,
},
{
path: '/users',
route: userRoute,
},
];
const devRoutes = [
...defaultRoutes,
{
path: '/docs',
route: docsRoute,
},
];
if (config.env === 'production') {
defaultRoutes.forEach((route) => {
router.use(route.path, route.route);
});
} else {
devRoutes.forEach((route) => {
router.use(route.path, route.route);
});
}
module.exports = router; I haven't tested it in production, but in development mode it works just fine, as expected. Would you recommend a better approach to disable swagger-ui in production? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @engineervix thank you for the kind words. I'm glad you like the boilerplate. Also, many thanks for this great suggestion. I really like it. Would you like to create a pull request? I'd be happy to merge it. One thing I would change though is to keep |
Beta Was this translation helpful? Give feedback.
Hi @engineervix thank you for the kind words. I'm glad you like the boilerplate. Also, many thanks for this great suggestion. I really like it.
Would you like to create a pull request? I'd be happy to merge it.
One thing I would change though is to keep
defaultRoutes
anddevRoutes
as separate arrays, and I would always add all thedefaultRoutes
. Only whenconfig.env !== 'production
then I would also add thedevRoutes
.