Skip to content

Commit fec4a0d

Browse files
fix: remove hardcoded VITE_API_URL and adjust socket connection logic
The VITE_API_URL environment variable was being hardcoded in the infrastructure script, which is unnecessary for production. The frontend socket connection logic has been updated to use a relative path ('/') in production while maintaining localhost for development. This ensures proper WebSocket connections in both environments without requiring explicit backend URLs in production.
1 parent 9c73045 commit fec4a0d

3 files changed

Lines changed: 2 additions & 3 deletions

File tree

apps/infra/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ cd /home/ec2-user/app
106106
cat <<EOT >> .env
107107
NODE_ENV=production
108108
REDIS_URL=redis://${redisHost}:6379
109-
VITE_API_URL=http://localhost:3000
110109
EOT
111110
112111
chown -R ec2-user:ec2-user /home/ec2-user/app

apps/web/src/pages/OverlayPage.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('OverlayPage', () => {
3030
</MemoryRouter>
3131
);
3232

33-
const mSocket = io('http://localhost');
33+
const mSocket = io('/');
3434
expect(io).toHaveBeenCalled();
3535

3636
// Simulate connect event

apps/web/src/pages/OverlayPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function OverlayPage() {
6262
if (!channel) return;
6363

6464
// Connect to WebSocket (relative if same domain, or specify backend URL in dev)
65-
const socketUrl = import.meta.env.VITE_API_URL || 'http://localhost:3000';
65+
const socketUrl = import.meta.env.VITE_API_URL || (import.meta.env.DEV ? 'http://localhost:3000' : '/');
6666
const socket = io(socketUrl);
6767
socketRef.current = socket;
6868

0 commit comments

Comments
 (0)