Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] ✨ : swagger 보안 적용 #377

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion BE/musicspot/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@ import { AppModule } from './app.module';
import { ValidationPipe, VersioningType } from '@nestjs/common';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AllExceptionFilter } from './filters/exception.filter';
import * as expressBasicAuth from 'express-basic-auth';
import * as dotenv from 'dotenv';

dotenv.config();
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableVersioning({
type: VersioningType.URI,
});
app.use(
//이 부분 추가
['/api'], // docs(swagger end point)에 진입시
expressBasicAuth({
challenge: true,
users: {
[process.env.SWAGGER_USER]: process.env.SWAGGER_PASSWORD, // 지정된 ID/비밀번호
},
}),
);
const config = new DocumentBuilder()
.setTitle('Music Spot') // 문서의 제목
.setDescription('iOS01 Music Spot App API') // 문서의 간단한 설명
.setVersion('2.0') // API의 버전(업데이트 버전)
.addTag('Music Spot')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
SwaggerModule.setup('api', app, document, {
swaggerOptions: {
persistAuthorization: true,
},
});
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"@nestjs/mongoose": "^10.0.2",
"express-basic-auth": "^1.2.1",
"mongoose": "^8.0.0"
}
}