Skip to content

Commit

Permalink
fix: 앱모듈에서 앱 인터셉터로 글로벌로 적용해주기
Browse files Browse the repository at this point in the history
  • Loading branch information
peageon committed Dec 5, 2023
1 parent e0476ba commit ae9367e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 35 deletions.
7 changes: 6 additions & 1 deletion back/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { AuthModule } from './modules/auth/auth.module';
import typeOrmConfig from './config/ormconfig';
import { JwtModule } from '@nestjs/jwt';
import { UserModule } from './modules/user/user.module';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { ControllerLoggerInterceptor } from './common/interceptors/log.interceptor';

@Module({
imports: [
Expand All @@ -17,6 +19,9 @@ import { UserModule } from './modules/user/user.module';
})
],
controllers: [AppController],
providers: [AppService]
providers: [
AppService,
{ provide: APP_INTERCEPTOR, useClass: ControllerLoggerInterceptor }
]
})
export class AppModule {}
2 changes: 1 addition & 1 deletion back/src/common/interceptors/log.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ControllerLoggerInterceptor implements NestInterceptor {
const logger = new Logger(controllerName);
const request = context.switchToHttp().getRequest();
const method = request.method;
const url = request.url;
const url = request.originalUrl;
const start = Date.now();
logger.verbose(`>>> IN: ${method} ${url}`);
return next.handle().pipe(
Expand Down
17 changes: 1 addition & 16 deletions back/src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import {
Controller,
Get,
Req,
Res,
UseGuards,
UseInterceptors
} from '@nestjs/common';
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { payload } from './auth.service';
import { ControllerLoggerInterceptor } from 'src/common/interceptors/log.interceptor';

@ApiTags('Oauth API')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Get('google')
@UseInterceptors(ControllerLoggerInterceptor)
@ApiOperation({
summary: 'Google 로그인 요청 API',
description: 'Google OAuth API에 로그인 요청을 보냅니다.'
Expand All @@ -34,7 +25,6 @@ export class AuthController {
async googleLogin(): Promise<void> {}

@Get('google/redirect')
@UseInterceptors(ControllerLoggerInterceptor)
@UseGuards(AuthGuard('google'))
@ApiResponse({
status: 200,
Expand All @@ -55,7 +45,6 @@ export class AuthController {
}

@Get('naver')
@UseInterceptors(ControllerLoggerInterceptor)
@ApiOperation({
summary: 'Naver 로그인 요청 API',
description: 'Naver OAuth API에 로그인 요청을 보냅니다.'
Expand All @@ -72,7 +61,6 @@ export class AuthController {
async naverLogin(): Promise<void> {}

@Get('naver/redirect')
@UseInterceptors(ControllerLoggerInterceptor)
@UseGuards(AuthGuard('naver'))
@ApiResponse({
status: 200,
Expand All @@ -93,7 +81,6 @@ export class AuthController {
}

@Get('kakao')
@UseInterceptors(ControllerLoggerInterceptor)
@ApiOperation({
summary: 'Kakao 로그인 요청 API',
description: 'Kakao OAuth API에 로그인 요청을 보냅니다.'
Expand All @@ -110,7 +97,6 @@ export class AuthController {
async kakaoLogin(): Promise<void> {}

@Get('kakao/redirect')
@UseInterceptors(ControllerLoggerInterceptor)
@UseGuards(AuthGuard('kakao'))
@ApiResponse({
status: 200,
Expand All @@ -132,7 +118,6 @@ export class AuthController {
}

@Get('logout')
@UseInterceptors(ControllerLoggerInterceptor)
@ApiResponse({
status: 200,
description: '로그아웃 성공'
Expand Down
9 changes: 1 addition & 8 deletions back/src/modules/message/message.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
HttpCode,
UseGuards,
Put,
Req,
UseInterceptors
Req
} from '@nestjs/common';
import { MessageService } from './message.service';
import { ReqCreateMessageDto } from './dto/request/req-create-message.dto';
Expand All @@ -32,7 +31,6 @@ import { JWTGuard } from 'src/common/guards/jwt.guard';
import { UpdateMessageLocationDto } from './dto/update-message-location.dto';
import { JWTRequest } from 'src/common/interface/request.interface';
import { ClovaService } from './clova.service';
import { ControllerLoggerInterceptor } from 'src/common/interceptors/log.interceptor';
@ApiTags('Message API')
@Controller('message')
export class MessageController {
Expand All @@ -42,7 +40,6 @@ export class MessageController {
) {}

@Post('/:snowball_id')
@UseInterceptors(ControllerLoggerInterceptor)
@HttpCode(201)
@ApiOperation({
summary: '메세지 생성 API',
Expand Down Expand Up @@ -74,7 +71,6 @@ export class MessageController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Delete(':message_id')
@HttpCode(204)
Expand All @@ -100,7 +96,6 @@ export class MessageController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Get('/')
@HttpCode(200)
Expand All @@ -123,7 +118,6 @@ export class MessageController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Put('/:message_id/open')
@HttpCode(200)
Expand Down Expand Up @@ -154,7 +148,6 @@ export class MessageController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Put('/:message_id/location')
@ApiOperation({
Expand Down
5 changes: 0 additions & 5 deletions back/src/modules/snowball/snowball.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import { JWTGuard } from 'src/common/guards/jwt.guard';
import { UpdateMainDecoDto } from './dto/update-main-decoration.dto';
import { JWTRequest } from '../../common/interface/request.interface';
import { hasJWTInterceptor } from '../../common/interceptors/hasJwt.interceptor';
import { ControllerLoggerInterceptor } from '../../common/interceptors/log.interceptor';

@ApiTags('Snowball API')
@Controller('snowball')
export class SnowballController {
constructor(private readonly snowballService: SnowballService) {}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Post()
@HttpCode(201)
Expand All @@ -61,7 +59,6 @@ export class SnowballController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Put('/:snowball_id')
@HttpCode(200)
Expand Down Expand Up @@ -89,7 +86,6 @@ export class SnowballController {
}

@Get('/:snowball_id')
@UseInterceptors(ControllerLoggerInterceptor)
@UseInterceptors(hasJWTInterceptor)
@HttpCode(200)
@ApiResponse({
Expand All @@ -114,7 +110,6 @@ export class SnowballController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Put('/:snowball_id/decoration')
@ApiResponse({
Expand Down
5 changes: 1 addition & 4 deletions back/src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import { ResInfoDto } from './dto/response/res-info.dto';
import { NicknameDto } from './dto/nickname.dto';
import { JWTRequest } from 'src/common/interface/request.interface';
import { TransactionInterceptor } from 'src/common/interceptors/transaction.interceptor';
import { ControllerLoggerInterceptor } from 'src/common/interceptors/log.interceptor';

@ApiTags('User API')
@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor)
@ApiCookieAuth('access_token')
@Get()
@ApiOperation({
Expand All @@ -46,7 +44,6 @@ export class UserController {
}

@Get('/:auth_id')
@UseInterceptors(ControllerLoggerInterceptor)
@ApiOperation({
summary: '방문자 유저 조회 API',
description: '방문자가 접속한 유저의 정보를 반환합니다'
Expand All @@ -65,7 +62,7 @@ export class UserController {
}

@UseGuards(JWTGuard)
@UseInterceptors(ControllerLoggerInterceptor, TransactionInterceptor)
@UseInterceptors(TransactionInterceptor)
@ApiCookieAuth('access_token')
@Put('/nickname')
@ApiBody({ type: NicknameDto })
Expand Down

0 comments on commit ae9367e

Please sign in to comment.