Skip to content

Commit

Permalink
fix(cors): 연결오류해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jsween5723 committed Dec 2, 2023
1 parent 35b9341 commit f15d95e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/all/all.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/common/common.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class CommonGateway
protected abstract getRoomId(client: Socket): Promise<string>;

protected async getUser(client: Socket) {
if (!client.handshake.auth.id) {
if (!client.handshake.query.token) {
client.emit('error', {
code: 'LOGIN_REQUIRED',
message: '로그인이 필요합니다.',
Expand All @@ -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<any> {
console.log('disconnect');
client.disconnect();
}

handleConnection(client: any, ...args: any[]): any {
Expand Down
2 changes: 1 addition & 1 deletion src/jwt/jwt.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class JwtAuthGuard implements CanActivate {
if (parts.length !== 2 || parts[0] !== 'Bearer') {
return null;
}

console.log(parts);
return parts[1];
}
}
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
},
});
Expand Down

0 comments on commit f15d95e

Please sign in to comment.