fix: route API/WS to remote server even from localhost
Build & Deploy / build-and-push (backend) (push) Successful in 7m26s
Build & Deploy / build-and-push (proxy) (push) Successful in 2m16s
Build & Deploy / build-and-push (discord-gateway) (push) Canceled after 36m39s
Build & Deploy / build-and-push (backend) (push) Successful in 7m26s
Build & Deploy / build-and-push (proxy) (push) Successful in 2m16s
Build & Deploy / build-and-push (discord-gateway) (push) Canceled after 36m39s
Development should use the production API/WS endpoints (imphnen.asepharyana.my.id) regardless of where the frontend dev server runs. 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
7bebb23c1d
commit
1eca1e819a
@@ -8,19 +8,20 @@ export class ApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
function getBaseUrl(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
const protocol = window.location.protocol.replace(":", "");
|
||||
const hostname = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
const REMOTE_API = "https://imphnen.asepharyana.my.id";
|
||||
|
||||
// In local dev, frontend (port 3000) proxies API calls to backend (port 3001)
|
||||
function getBaseUrl(): string {
|
||||
if (typeof window === "undefined") return REMOTE_API;
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
// In local dev, route API calls to the remote server
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
||||
const apiPort = port === "3000" ? "3001" : port;
|
||||
return `${protocol}://${hostname}:${apiPort}`;
|
||||
return REMOTE_API;
|
||||
}
|
||||
|
||||
// Production: nginx proxies /api/* to backend
|
||||
// Production: nginx proxies /api/* to backend on the same host
|
||||
const protocol = window.location.protocol.replace(":", "");
|
||||
const port = window.location.port;
|
||||
return `${protocol}://${hostname}${port ? `:${port}` : ""}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,20 @@ import type { WsEvent, WsStatus } from "./types";
|
||||
|
||||
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 hostname = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
const REMOTE_WS = "wss://imphnen.asepharyana.my.id/ws";
|
||||
|
||||
// In local dev, WS server runs on port 3001 alongside the backend
|
||||
function getWsUrl(): string {
|
||||
if (typeof window === "undefined") return REMOTE_WS;
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
// Always route WS through the remote server (even from local dev)
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
||||
const wsPort = port === "3000" ? "3001" : port;
|
||||
return `${protocol}://${hostname}:${wsPort}/ws`;
|
||||
return REMOTE_WS;
|
||||
}
|
||||
|
||||
// Production: nginx proxies /ws/* to backend
|
||||
// Production: nginx proxies /ws/* to backend on the same host
|
||||
const protocol = window.location.protocol === "https:" ? "wss" : "ws";
|
||||
const port = window.location.port;
|
||||
return `${protocol}://${hostname}${port ? `:${port}` : ""}/ws`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user