Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ interface ApiQueryResult {
}

function getApiBaseUrl() {
// Explicit override always wins (set this env var in Railway to point at the
// internal backend DNS, e.g. http://thesphere.railway.internal:8000).
if (process.env.NEXT_PUBLIC_API_BASE_URL) {
return process.env.NEXT_PUBLIC_API_BASE_URL;
}

if (typeof window !== "undefined") {
return `${window.location.protocol}//${window.location.hostname}:8000`;
// Server-side (SSR / RSC): use the Railway-internal DNS so the request never
// leaves the private network. Falls back to the well-known internal address
// when SPHERE_BACKEND_URL is not explicitly configured.
if (typeof window === "undefined") {
return (
process.env.SPHERE_BACKEND_URL ?? "http://thesphere.railway.internal:8000"
);
}

// Client-side in local development: proxy through localhost.
return "http://localhost:8000";
}

Expand Down