Cody2333 / koa-swagger-decorator

using decorator to automatically generate swagger doc for koa-router
350 stars 81 forks source link

how to disenable swagger in production? #121

Closed dengdan99 closed 3 years ago

dengdan99 commented 3 years ago

i can't found some configuration about close or disenable this

os, i do like this


const isPordMode = process.env.NODE_ENV == "production"
let protectedRouter: Router | SwaggerRouter
if (isPordMode) {
    protectedRouter = new Router()
} else {
    protectedRouter = new SwaggerRouter()
}

protectedRouter.get('/managers', master.getMasters)
protectedRouter.post('/manager', master.createMaster)
protectedRouter.get('/managers/:id', master.getMaster)

if (protectedRouter instanceof SwaggerRouter) {
    protectedRouter.swagger({
        title: '接口文档',
        description: '描述',
        version: '1.2.3'
    })
    protectedRouter.mapDir(path.resolve(__dirname, '../controllers/'))
}

export { protectedRouter }
Cody2333 commented 3 years ago
if (!isProdMode) {
 router.swagger(...)
}

swagger endpoint is registered to router by calling router.swagger(...), so if you want to disable it , you can just call router.swagger in develop mode.

dengdan99 commented 3 years ago

ok done 谢谢