Skip to content

Commit

Permalink
[FIX] cors 해결 (#122)
Browse files Browse the repository at this point in the history
* fix: rank가 0부터 시작하므로 1을 추가하여 프론트로 반환 #8

* [FEAT] 랭킹 조회 시 DB 정렬 로직 추가

* [FEAT] update BE-config

* [FEAT] update 42 env

* [FEAT] health check api

* [CHORE] BE-config 업데이트 및 health api 수정

* [FIX] mkcert 파일 httpsOptions 삭제

* [FIX] 중복로그인 시 에러 반환

* [FIX] mute 시간 10->30초로 변경

* [CHORE] TODO 주석 삭제

* [FIX] socket secure 삭제 및 중복로그인 에러 수정

* [FIX] 중복로그인 에러 메시지 WS_DUPLICATE_LOGIN_ERROR 로 수정

* [FIX] cors 에러 해결
  • Loading branch information
yubinquitous authored May 6, 2024
1 parent 8577505 commit 7d44295
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/channels/channels.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
import Redis from 'ioredis';
import { Server } from 'socket.io';
import { UserStatus } from 'src/common/enum';
import { EVENT_USER_STATUS } from 'src/common/events';
import { EVENT_ERROR, EVENT_USER_STATUS } from 'src/common/events';
import { WSBadRequestException } from 'src/common/exception/custom-exception';
import { WsFilter } from 'src/common/exception/custom-ws-exception.filter';
import { WS_DUPLICATE_LOGIN_ERROR } from 'src/common/exception/error-code';
import { FriendsRepository } from 'src/friends/friends.repository';
import { User } from 'src/user-repository/entities/user.entity';
import { UsersRepository } from 'src/user-repository/users.repository';
Expand Down Expand Up @@ -74,6 +73,9 @@ export class ChannelsGateway
console.log('socket이 이미 존재합니다.');
const socket = await this.isSocketConnected(user.channelSocketId);
if (socket) {
this.server
.to(socket.id)
.emit(EVENT_ERROR, 'WS_DUPLICATE_LOGIN_ERROR');
socket.disconnect();
} else {
await this.usersRepository.update(user.id, {
Expand Down
1 change: 1 addition & 0 deletions src/common/adapter/socket-io.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SocketIoAdapter extends IoAdapter {
new RegExp(
`/^http:\/\/192\.168\.1\.([1-9]|[1-9]\d):${clientPort}$/`,
),
`https://tscenping.shop`,
],
};

Expand Down
9 changes: 4 additions & 5 deletions src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@nestjs/websockets';
import Redis from 'ioredis';
import { Server, Socket } from 'socket.io';
import { WS_DUPLICATE_LOGIN_ERROR } from 'src/common/exception/error-code';
import { ChannelsGateway } from '../channels/channels.gateway';
import { SocketWithAuth } from '../common/adapter/socket-io.adapter';
import { K } from '../common/constants';
Expand Down Expand Up @@ -85,16 +84,16 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
const user = client.user;
if (!user || !client.id) return client.disconnect();
else if (user.gameSocketId) {
console.log('game socket 갈아끼운다 ~?!');
console.log('game socket이 이미 존재합니다.');
const socket = this.userIdToClient.get(user.id);
if (socket) {
const result = await this.isSocketConnected(socket);
if (result) {
// 이미 로그인된 유저의 경우, 기존 소켓을 disconnect한다.
this.server
.to(socket.id)
.emit(EVENT_ERROR, WS_DUPLICATE_LOGIN_ERROR);
socket.disconnect();
.to(result.id)
.emit(EVENT_ERROR, 'WS_DUPLICATE_LOGIN_ERROR');
result.disconnect();
} else this.userIdToClient.delete(user.id);
} else {
await this.usersRepository.update(user.id, {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function bootstrap() {
app.enableCors({
credentials: true,
// origin: 'https://localhost:3003',
origin: true,
origin: ['http://localhost:3003', 'https://tscenping.shop'],
});
app.use(cookieParser());

Expand Down

0 comments on commit 7d44295

Please sign in to comment.