Reputation: 73
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
instead of this, i want to use inside callback function of NodeJS Need to set basepath dynamically inside callback function.
app.use('/swagger', function(req,res) {
swaggerDocument.basepath = "/pet/details",
res.send(swaggerUi.serve, swaggerUi.setup(swaggerDocument));
});
Please help me to resolve this..
Upvotes: 3
Views: 1478
Reputation: 73
Found the solution,
Used callback function like this,
router.use(
swaggerUi.serve,
function(req, res) {
swaggerDocument.host = req.get('host'); // Replace hardcoded host information in swagger file
swaggerDocument.schemes = [req.protocol]; // Replace hardcoded protocol information in Swagger file
swaggerUi.setup(swaggerDocument)(req, res);
}
});
Upvotes: 3