fix: route API/WS calls to backend port 3001 in local dev
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 36s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m59s
Build & Deploy / build-and-push (backend) (push) Successful in 3m47s
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 36s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m59s
Build & Deploy / build-and-push (backend) (push) Successful in 3m47s
Detect localhost and redirect API calls and WebSocket connections from frontend port (3000) to backend port (3001). Production behavior (via nginx proxy) unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
59dc27733e
commit
b8f358861e
@@ -11,8 +11,17 @@ export class ApiError extends Error {
|
||||
function getBaseUrl(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
const protocol = window.location.protocol.replace(":", "");
|
||||
const host = window.location.host;
|
||||
return `${protocol}://${host}`;
|
||||
const hostname = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
|
||||
// In local dev, frontend (port 3000) proxies API calls to backend (port 3001)
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
||||
const apiPort = port === "3000" ? "3001" : port;
|
||||
return `${protocol}://${hostname}:${apiPort}`;
|
||||
}
|
||||
|
||||
// Production: nginx proxies /api/* to backend
|
||||
return `${protocol}://${hostname}${port ? `:${port}` : ""}`;
|
||||
}
|
||||
|
||||
export async function apiRequest<T>(
|
||||
|
||||
@@ -5,8 +5,17 @@ type WsEventCallback = (event: WsEvent) => void;
|
||||
function getWsUrl(): string {
|
||||
if (typeof window === "undefined") return "ws://localhost:3001/ws";
|
||||
const protocol = window.location.protocol === "https:" ? "wss" : "ws";
|
||||
const host = window.location.host;
|
||||
return `${protocol}://${host}/ws`;
|
||||
const hostname = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
|
||||
// In local dev, WS server runs on port 3001 alongside the backend
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
||||
const wsPort = port === "3000" ? "3001" : port;
|
||||
return `${protocol}://${hostname}:${wsPort}/ws`;
|
||||
}
|
||||
|
||||
// Production: nginx proxies /ws/* to backend
|
||||
return `${protocol}://${hostname}${port ? `:${port}` : ""}/ws`;
|
||||
}
|
||||
|
||||
export class WsConnection {
|
||||
|
||||
Reference in New Issue
Block a user