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
@@ -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