Showing posts with label TypeScript. Show all posts
Showing posts with label TypeScript. Show all posts

May 26, 2022

How to securing access to of Swagger with HTTP Basic Auth? With example if TypeScript NestJS.



- 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! 

The Future of Technology: Emerging Trends to Watch in 2025

Introduction As we navigate through 2025, the technological landscape continues to evolve at an unprecedented pace. Innovations that once se...