-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor/#106/folder
- Loading branch information
Showing
5 changed files
with
92 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
ClassSerializerInterceptor, | ||
Injectable, | ||
ValidationPipe, | ||
} from "@nestjs/common"; | ||
import { Reflector } from "@nestjs/core"; | ||
import { NestExpressApplication } from "@nestjs/platform-express"; | ||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; | ||
import * as cookieParser from "cookie-parser"; | ||
|
||
@Injectable() | ||
export class BootstrapService { | ||
setCors(app: NestExpressApplication) { | ||
app.enableCors({ | ||
origin: true, | ||
credentials: true, | ||
}); | ||
} | ||
|
||
setProxy(app: NestExpressApplication) { | ||
app.set("trust proxy", true); | ||
} | ||
|
||
setSwagger(app: NestExpressApplication) { | ||
const config = new DocumentBuilder() | ||
.setTitle("Modern World API") | ||
.setDescription("API of Modern World") | ||
.setVersion("0.1") | ||
.addCookieAuth( | ||
"refreshToken-cookie", | ||
{ | ||
type: "http", | ||
in: "Header", | ||
scheme: "Bearer", | ||
description: "리프레시 토큰 입력", | ||
}, | ||
"refresh-token", | ||
) | ||
.addBearerAuth( | ||
{ | ||
type: "http", | ||
scheme: "bearer", | ||
name: "JWT", | ||
description: "액세스 토큰 입력", | ||
in: "header", | ||
}, | ||
"access-token", | ||
) | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, config); | ||
SwaggerModule.setup("api", app, document); | ||
} | ||
|
||
useGlobalPipes(app: NestExpressApplication) { | ||
app.useGlobalPipes(new ValidationPipe({ transform: true })); | ||
} | ||
|
||
useGlobalInterceptors(app: NestExpressApplication) { | ||
app.useGlobalInterceptors( | ||
new ClassSerializerInterceptor(app.get(Reflector)), | ||
); | ||
} | ||
|
||
useCookieParser(app: NestExpressApplication) { | ||
app.use(cookieParser()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,23 @@ | ||
import { NestFactory, Reflector } from "@nestjs/core"; | ||
import { NestFactory } from "@nestjs/core"; | ||
import { AppModule } from "./app.module"; | ||
import { ClassSerializerInterceptor, ValidationPipe } from "@nestjs/common"; | ||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; | ||
import { winstonLogger } from "./common/utils/logger/logger.config"; | ||
import * as cookieParser from "cookie-parser"; | ||
import { NestExpressApplication } from "@nestjs/platform-express"; | ||
import { BootstrapService } from "./bootstrap.service"; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create<NestExpressApplication>(AppModule, { | ||
logger: winstonLogger, | ||
}); | ||
const bootstrap = app.get(BootstrapService); | ||
|
||
app.enableCors({ | ||
origin: true, | ||
credentials: true, | ||
}); | ||
|
||
app.set("trust proxy", true); | ||
|
||
const config = new DocumentBuilder() | ||
.setTitle("Modern World API") | ||
.setDescription("API of Modern World") | ||
.setVersion("0.1") | ||
.addCookieAuth( | ||
"refreshToken-cookie", | ||
{ | ||
type: "http", | ||
in: "Header", | ||
scheme: "Bearer", | ||
description: "리프레시 토큰 입력", | ||
}, | ||
"refresh-token", | ||
) | ||
.addBearerAuth( | ||
{ | ||
type: "http", | ||
scheme: "bearer", | ||
name: "JWT", | ||
description: "액세스 토큰 입력", | ||
in: "header", | ||
}, | ||
"access-token", | ||
) | ||
.build(); | ||
bootstrap.setCors(app); | ||
bootstrap.setProxy(app); | ||
bootstrap.setSwagger(app); | ||
bootstrap.useGlobalPipes(app); | ||
bootstrap.useGlobalInterceptors(app); | ||
bootstrap.useCookieParser(app); | ||
|
||
const document = SwaggerModule.createDocument(app, config); | ||
SwaggerModule.setup("api", app, document); | ||
|
||
app.useGlobalPipes(new ValidationPipe({ transform: true })); | ||
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); | ||
app.use(cookieParser()); | ||
await app.listen(3000); | ||
} | ||
|
||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters