You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// main.tsimport{NestExpressApplication,ExpressAdapter}from'@nestjs/platform-express';import{Express,NextFunction,Request,Response}from'express';importcreateApplicationfrom'express';/** * Fix: swagger.json is not secured * @param expressApp */functionsetupSwaggerProtection(expressApp: Express){constprotection=(req: Request,res: Response,next: NextFunction)=>{constauthHeader=req.headers.authorization;if(authHeader){constcredentials=authHeader.split(' ')[1];const[username,password]=Buffer.from(credentials,'base64').toString().split(':');if(// replace with your auth paramsusername==='USER'&&password==='PASSWORD'){returnnext();}}res.setHeader('WWW-Authenticate','Basic realm="Restricted Area"');res.status(401).send('Authentication required');};// Replace openapi with your actual Redoc pathexpressApp.use('/openapi/swagger.json',protection);}asyncfunctionbootstrap(){constexpressApp=createApplication();setupSwaggerProtection(expressApp);constapp=awaitNestFactory.create<NestExpressApplication>(AppModule,newExpressAdapter(expressApp),{bufferLogs: true,},);// ...
When I'm protect my documentation with
this works for main page, but doesn't protect access to swagger.json!!!
See related
#19 (comment)
The text was updated successfully, but these errors were encountered: