feat: Basic setup with auth
This commit is contained in:
37
src/main.ts
37
src/main.ts
@@ -1,10 +1,47 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('Kaa Khane')
|
||||
.setDescription(`API Documentation for Kaa Khane`)
|
||||
.setVersion('0.0.1')
|
||||
.addGlobalResponse(
|
||||
{
|
||||
status: 500,
|
||||
description: 'Internal Server Error',
|
||||
},
|
||||
{
|
||||
status: 401,
|
||||
description: 'Unauthorized',
|
||||
},
|
||||
{
|
||||
status: 403,
|
||||
description: 'Forbidden',
|
||||
},
|
||||
)
|
||||
.addBearerAuth(
|
||||
{
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
},
|
||||
'access-token',
|
||||
)
|
||||
.build();
|
||||
|
||||
const documentFactory = () =>
|
||||
SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup('/docs', app, documentFactory, {
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
},
|
||||
});
|
||||
|
||||
const config = app.get(ConfigService);
|
||||
const port = config.get<number>('PORT') ?? 3000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user