From 9b4305f76e04a85b2c5047b117efb9f7280d9e03 Mon Sep 17 00:00:00 2001 From: romansharapov19 <95644495+romansharapov19@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:49:02 +0100 Subject: [PATCH] fix: add the exact route to socket cors origin (#108) --- packages/api/src/chats/adapters/redis-io.adapter.ts | 1 + packages/api/src/chats/chat-socket.gateway.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/api/src/chats/adapters/redis-io.adapter.ts b/packages/api/src/chats/adapters/redis-io.adapter.ts index d63e548..329a563 100644 --- a/packages/api/src/chats/adapters/redis-io.adapter.ts +++ b/packages/api/src/chats/adapters/redis-io.adapter.ts @@ -23,6 +23,7 @@ export class RedisIoAdapter extends IoAdapter { } createIOServer(port: number, options?: ServerOptions): any { + options.cors = { origin: this.configService.get('FRONTEND_ORIGIN_URL') }; const server = super.createIOServer(port, options); server.adapter(this.adapterConstructor); return server; diff --git a/packages/api/src/chats/chat-socket.gateway.ts b/packages/api/src/chats/chat-socket.gateway.ts index c1eaec9..3a8e493 100644 --- a/packages/api/src/chats/chat-socket.gateway.ts +++ b/packages/api/src/chats/chat-socket.gateway.ts @@ -17,7 +17,7 @@ import { Server, Socket } from 'socket.io'; @WebSocketGateway({ cors: { - origin: '*', + credentials: true, }, }) export class ChatSocketGateway {