Skip to content

Commit

Permalink
Merge pull request #145 from modern-agile-team/refactor/#106/folder
Browse files Browse the repository at this point in the history
Refactor/#106/folder
  • Loading branch information
Contingency1 authored Sep 4, 2024
2 parents 1125141 + 8813e9c commit d437040
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LoggerModule } from "./common/utils/logger/logger.module";
import { SseModule } from "./sse/sse.module";
import { RedisModule } from "./auth/redis/redis.module";
import { ApiModule } from "./api.module";
import { BootstrapService } from "./bootstrap.service";

@Module({
imports: [
Expand All @@ -20,7 +21,7 @@ import { ApiModule } from "./api.module";
ApiModule,
],
// isGlobal: ConfigModule을 AppModul 이외의 모듈에서 반복 import할 필요 없는 전역 모듈로 설정.
providers: [ConfigService],
providers: [ConfigService, BootstrapService],
// 앵간하면 nestJS에서 권장하는 방법인 ConfigService를 이용하여 환경변수 값을 사용해야함.
})
export class AppModule {}
68 changes: 68 additions & 0 deletions src/bootstrap.service.ts
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());
}
}
1 change: 0 additions & 1 deletion src/likes/likes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
NotFoundException,
} from "@nestjs/common";
import { LikesRepository } from "./likes.repository";
import { UsersRepository } from "src/users/users.repository";
import { LegendsRepository } from "src/legends/legends.repository";
import { PrismaService } from "src/prisma/prisma.service";
import { SseService } from "src/sse/sse.service";
Expand Down
52 changes: 10 additions & 42 deletions src/main.ts
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();
23 changes: 12 additions & 11 deletions src/users/users-swagger/get-one-user.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,32 @@ export function ApiGetOneUser() {
JSON: {
example: {
no: 1,
nickname: "1번닉네임",
description: "1번소개",
currentPoint: 0,
accumulationPoint: 0,
image: "1번이미지",
socialName: "김은우",
nickname: "끼무뗭떵이",
description: "끼무뗭",
currentPoint: 29200,
accumulationPoint: 64200,
image: "유저소셜이미지",
legend: {
likeCount: 7,
likeCount: 1,
},
characterLocker: [
{
character: {
no: 1,
image: "1번 dog 이미지",
no: 10,
image: "캐릭터 이미지",
},
},
],
userAchievement: [
{
achievement: {
title: "커뮤 초보자",
level: "one",
title: "레전드",
level: "three",
},
},
],
chance: 10,
chance: 7,
},
},
},
Expand Down

0 comments on commit d437040

Please sign in to comment.