From f15d95ebf6c4278bf819ec1daa7e1c215bf6a625 Mon Sep 17 00:00:00 2001 From: jsween5723 Date: Sat, 2 Dec 2023 12:11:40 +0900 Subject: [PATCH] =?UTF-8?q?fix(cors):=20=EC=97=B0=EA=B2=B0=EC=98=A4?= =?UTF-8?q?=EB=A5=98=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/all/all.filter.ts | 1 + src/common/common.gateway.ts | 4 +--- src/jwt/jwt.guard.ts | 2 +- src/main.ts | 6 +++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/all/all.filter.ts b/src/all/all.filter.ts index 80d8ecb..d7bf782 100644 --- a/src/all/all.filter.ts +++ b/src/all/all.filter.ts @@ -17,6 +17,7 @@ import { BaseErrorResponse, BaseResponse } from '../common/base-response'; @Catch() export class AllExceptionsFilter implements ExceptionFilter { private logger = new Logger('Exception'); + catch(exception: HttpException, host: ArgumentsHost): void { const ctx = host.switchToHttp(); this.logger.error(exception); diff --git a/src/common/common.gateway.ts b/src/common/common.gateway.ts index 35816b3..b0035db 100644 --- a/src/common/common.gateway.ts +++ b/src/common/common.gateway.ts @@ -23,7 +23,7 @@ export abstract class CommonGateway protected abstract getRoomId(client: Socket): Promise; protected async getUser(client: Socket) { - if (!client.handshake.auth.id) { + if (!client.handshake.query.token) { client.emit('error', { code: 'LOGIN_REQUIRED', message: '로그인이 필요합니다.', @@ -46,14 +46,12 @@ export abstract class CommonGateway } catch (e) { console.log(e.response); client.emit('error', e.response); - } finally { client.disconnect(); } } async handleDisconnect(@ConnectedSocket() client: Socket): Promise { console.log('disconnect'); - client.disconnect(); } handleConnection(client: any, ...args: any[]): any { diff --git a/src/jwt/jwt.guard.ts b/src/jwt/jwt.guard.ts index d4d51e0..837cd3d 100644 --- a/src/jwt/jwt.guard.ts +++ b/src/jwt/jwt.guard.ts @@ -38,7 +38,7 @@ export class JwtAuthGuard implements CanActivate { if (parts.length !== 2 || parts[0] !== 'Bearer') { return null; } - + console.log(parts); return parts[1]; } } diff --git a/src/main.ts b/src/main.ts index e8180b6..0067b5c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ import * as https from 'https'; export const CONFIG_URL = `${process.env.SCHEME}://${process.env.ESC_CONFIG}${process.env.ESC_CONFIG_PORT}`; export const API_URL = `${process.env.SCHEME}://${process.env.ESC_API}${process.env.ESC_API_PORT}`; + export async function bootstrap() { const result = await fetch(`${CONFIG_URL}/meeting/default`).then((result) => result.json(), @@ -17,9 +18,8 @@ export async function bootstrap() { result.propertySources[0].source['cors-list'].split(', '); const app = await NestFactory.create(AppModule, { cors: { - origin: sourceElement, - methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', - allowedHeaders: ['Content-Type', 'Authorization', 'Cookie'], + origin: [...sourceElement, 'http://localhost:3001'], + methods: '*', credentials: true, }, });