- First set up NestJS TypeScrip basic project.
- Install express-basic-auth module using this command: npm i express-basic-auth
- import module on main.ts file
- Full example of main.ts file:
// import auth module
import * as basicAuth from 'express-basic-auth';
// Add HTTP Basic Auth
app.use(
basicAuth({
challenge: true,
users: {
defineUserName: 'passwrd here',
},
}),
);
// Main Code
const options = new DocumentBuilder()
.setTitle('First App')
.setSchemes('https')
.setDescription('Firsy App API documentation')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, options)
SwaggerModule.setup('docs', app, document, {
customSiteTitle: 'First App documentation',
});
Enjoy!