From 1c316a8cd33abdb122756698dedd4132d29e595b Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 18 Feb 2026 22:10:08 +0500 Subject: [PATCH] fix: use relative URLs for API and WebSocket in production Browser uses /api and /ws (same origin through Nginx), SSR falls back to localhost:3001 for development. Co-Authored-By: Claude Opus 4.6 --- apps/api/src/main.ts | 8 +++++++- apps/web/src/lib/api.ts | 2 +- apps/web/src/lib/socket.ts | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index a302bcc..f468a41 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -4,7 +4,13 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); - app.enableCors(); + app.enableCors({ + origin: [ + 'https://dev.reckue.com', + 'http://localhost:3000', + ], + credentials: true, + }); app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true })); app.setGlobalPrefix('api'); await app.listen(process.env.PORT ?? 3001); diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 59fcdd1..fdbda7e 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -1,4 +1,4 @@ -const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api'; +const API_URL = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? '/api' : 'http://localhost:3001/api'); class ApiClient { private token: string | null = null; diff --git a/apps/web/src/lib/socket.ts b/apps/web/src/lib/socket.ts index 6a506cc..221c453 100644 --- a/apps/web/src/lib/socket.ts +++ b/apps/web/src/lib/socket.ts @@ -1,6 +1,6 @@ import { io } from 'socket.io-client'; -const WS_URL = process.env.NEXT_PUBLIC_WS_URL || 'http://localhost:3001/ws'; +const WS_URL = process.env.NEXT_PUBLIC_WS_URL || (typeof window !== 'undefined' ? '/ws' : 'http://localhost:3001/ws'); export const socket = io(WS_URL, { autoConnect: false,