Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/chat/gateways/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ interface AuthenticatedSocket extends Socket {
path: '/socket.io',
transports: ['websocket'],
cors: {
origin: ['https://whatlunch.vercel.app'],
origin: [
'https://whatlunch.vercel.app',
'http://localhost:3000',
/https:\/\/whatlunch-.*\.vercel\.app$/,
],
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization', 'Cookie'],
},
})
export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
Expand Down Expand Up @@ -64,6 +69,18 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
.find((c) => c.startsWith('accessToken='))
?.split('=')[1];

if (!accessToken && typeof client.handshake.auth?.token === 'string') {
accessToken = client.handshake.auth.token;
if (accessToken) {
try {
accessToken = decodeURIComponent(accessToken);
} catch (error) {
console.error('[Gateway] 토큰 디코딩 오류:', error);
accessToken = undefined;
}
}
}

if (accessToken) {
try {
accessToken = decodeURIComponent(accessToken);
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ async function bootstrap() {

app.enableCors({
origin: (origin, callback) => {
const allowedOrigins = ['http://localhost:3000', 'https://whatlunch.vercel.app'];
const allowedOrigins = [
'http://localhost:3000',
'https://whatlunch.vercel.app',
/https:\/\/whatlunch-.*\.vercel\.app$/,
];

if (
!origin ||
Expand Down