@@ -3,6 +3,7 @@ import { NestFactory } from '@nestjs/core';
33import { DocumentBuilder , SwaggerModule } from '@nestjs/swagger' ;
44import { runMigrations } from '@marrylife/db' ;
55import cookieParser from 'cookie-parser' ;
6+ import basicAuth from 'express-basic-auth' ;
67import { AppModule } from './app.module' ;
78import { HttpExceptionFilter } from './common/filters/http-exception.filter' ;
89import { ResponseInterceptor } from './common/interceptors/response.interceptor' ;
@@ -31,16 +32,32 @@ async function bootstrap() {
3132 app . useGlobalInterceptors ( new ResponseInterceptor ( ) ) ;
3233 app . useGlobalFilters ( new HttpExceptionFilter ( ) ) ;
3334
34- const swaggerConfig = new DocumentBuilder ( )
35- . setTitle ( 'MarryLife API' )
36- . setDescription ( 'MarryLife API 문서' )
37- . setVersion ( '1.0.0' )
38- . addBearerAuth ( )
39- . build ( ) ;
40- const swaggerDocument = SwaggerModule . createDocument ( app , swaggerConfig ) ;
41- SwaggerModule . setup ( 'docs' , app , swaggerDocument , {
42- useGlobalPrefix : true ,
43- } ) ;
35+ const swaggerEnabled = process . env . SWAGGER_ENABLED !== 'false' ;
36+ if ( swaggerEnabled ) {
37+ const swaggerUser = process . env . SWAGGER_USER ;
38+ const swaggerPassword = process . env . SWAGGER_PASSWORD ;
39+ if ( swaggerUser && swaggerPassword ) {
40+ app . use (
41+ '/api/docs' ,
42+ basicAuth ( {
43+ users : { [ swaggerUser ] : swaggerPassword } ,
44+ challenge : true ,
45+ realm : 'MarryLife API Docs' ,
46+ } ) ,
47+ ) ;
48+ }
49+
50+ const swaggerConfig = new DocumentBuilder ( )
51+ . setTitle ( 'MarryLife API' )
52+ . setDescription ( 'MarryLife API 문서' )
53+ . setVersion ( '1.0.0' )
54+ . addBearerAuth ( )
55+ . build ( ) ;
56+ const swaggerDocument = SwaggerModule . createDocument ( app , swaggerConfig ) ;
57+ SwaggerModule . setup ( 'docs' , app , swaggerDocument , {
58+ useGlobalPrefix : true ,
59+ } ) ;
60+ }
4461
4562 const port = process . env . PORT ?? 4000 ;
4663 await app . listen ( port ) ;
0 commit comments