Skip to content

Commit 7303049

Browse files
fixing cors routes for netlify
1 parent 56e6866 commit 7303049

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

apps/api/src/chat/chat.gateway.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ import { ChatService } from './chat.service';
1616
import { JwtPayload } from '@/auth/interfaces/jwt-payload.interface';
1717
import { RoomsService } from './rooms.service';
1818

19-
@WebSocketGateway({ cors: { origin: '*' } })
19+
@WebSocketGateway({
20+
cors: {
21+
origin: [
22+
'https://mindsmesh.vercel.app',
23+
'https://mindsmesh-docker-api.onrender.com',
24+
'https://mindsmesh-freelance-platform.netlify.app',
25+
'https://mindsmesh-freelance-platform.netlify.app/',
26+
'http://localhost:5173',
27+
],
28+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
29+
credentials: true,
30+
},
31+
allowEIO3: true,
32+
transports: ['websocket', 'polling'],
33+
})
2034
export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
2135
@WebSocketServer()
2236
server: Server;
@@ -113,10 +127,10 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
113127
@SubscribeMessage('sendMessage')
114128
async handleSendMessage(
115129
@MessageBody()
116-
message: {
117-
id: string;
118-
senderId: string;
119-
receiverId: string;
130+
message: {
131+
id: string;
132+
senderId: string;
133+
receiverId: string;
120134
text: string;
121135
fileUrl?: string;
122136
fileName?: string;
@@ -166,7 +180,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
166180
isRead: savedMessage.isRead,
167181
fileUrl: savedMessage.fileUrl,
168182
fileName: savedMessage.fileName,
169-
fileType: savedMessage.fileType
183+
fileType: savedMessage.fileType,
170184
});
171185

172186
this.server.to(message.senderId).emit('messageDelivered', {

apps/api/src/main.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
66

77
async function bootstrap() {
88
const logger = new Logger('Bootstrap');
9-
9+
1010
const app = await NestFactory.create(AppModule);
1111

1212
// Set a global prefix for all routes
@@ -19,17 +19,22 @@ async function bootstrap() {
1919
app.use(bodyParser.json({ limit: '150mb' }));
2020
app.use(bodyParser.urlencoded({ limit: '150mb', extended: true }));
2121

22-
// Enable CORS
22+
// Enable CORS with updated configuration
2323
app.enableCors({
2424
origin: [
25-
'https://mindsmesh.vercel.app',
26-
'https://mindsmesh-freelance-platform.netlify.app/',
27-
'http://localhost:5173'
25+
'https://mindsmesh.vercel.app',
26+
'https://mindsmesh-docker-api.onrender.com',
27+
'https://mindsmesh-freelance-platform.netlify.app',
28+
'https://mindsmesh-freelance-platform.netlify.app/',
29+
'http://localhost:5173',
2830
],
29-
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
30-
allowedHeaders: 'Content-Type, Authorization',
31-
credentials: true,
31+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
32+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
33+
credentials: true,
34+
preflightContinue: false,
35+
optionsSuccessStatus: 204,
3236
});
37+
3338
// Swagger configuration
3439
const config = new DocumentBuilder()
3540
.setTitle('API Documentation')

0 commit comments

Comments
 (0)