diff --git a/backend/src/index.ts b/backend/src/index.ts index 6f11abe..865d8f5 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -23,9 +23,15 @@ import { setupSocketHandlers } from './services/socket'; const app = express(); const httpServer = createServer(app); +const allowedOrigins = [ + process.env.FRONTEND_URL, + 'https://coop.hobokenchicken.com', + 'http://172.20.1.238:3000' +].filter(Boolean) as string[]; + const io = new Server(httpServer, { cors: { - origin: process.env.FRONTEND_URL || 'http://localhost:3000', + origin: allowedOrigins, credentials: true } }); @@ -35,7 +41,7 @@ app.use(helmet({ crossOriginResourcePolicy: { policy: "cross-origin" } })); app.use(cors({ - origin: true, // Allow all origins in dev to fix the IP issue + origin: allowedOrigins, credentials: true })); diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 699aa39..4906833 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,6 +1,6 @@ import axios from 'axios'; -const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001'; +const API_URL = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? `${window.location.origin}/api` : 'http://localhost:3001/api'); export const api = axios.create({ baseURL: `${API_URL}/api`,