Skip to content
Open
Show file tree
Hide file tree
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: 11 additions & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ interface ApiQueryResult {
available: boolean;
}

const PRODUCTION_API_URL = "https://thesphere-production-4aea.up.railway.app";

function getApiBaseUrl() {
if (process.env.NEXT_PUBLIC_API_BASE_URL) {
return process.env.NEXT_PUBLIC_API_BASE_URL;
}

// In the browser, detect whether we're running in production (i.e. not on
// localhost / 127.0.0.1). NEXT_PUBLIC vars are baked at build time, so when
// Railway doesn't pass the build arg the env var is empty and we fall through
// to this runtime check instead of calling localhost from the user's browser.
if (typeof window !== "undefined") {
return `${window.location.protocol}//${window.location.hostname}:8000`;
const host = window.location.hostname;
if (host !== "localhost" && host !== "127.0.0.1") {
return PRODUCTION_API_URL;
}
return `${window.location.protocol}//${host}:8000`;
}

return "http://localhost:8000";
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/lib/intelligence/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,25 @@ export interface IntelligenceClientOptions {
signal?: AbortSignal;
}

const PRODUCTION_API_URL = "https://thesphere-production-4aea.up.railway.app";

function resolveBaseUrl(explicit: string | undefined): string {
if (explicit) {
return explicit.replace(/\/$/, "");
}
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_BASE_URL) {
return process.env.NEXT_PUBLIC_API_BASE_URL.replace(/\/$/, "");
}
// In the browser, detect whether we're running in production (i.e. not on
// localhost / 127.0.0.1). NEXT_PUBLIC vars are baked at build time, so when
// Railway doesn't pass the build arg the env var is empty and we fall through
// to this runtime check instead of calling localhost from the user's browser.
if (typeof window !== "undefined") {
return `${window.location.protocol}//${window.location.hostname}:8000`;
const host = window.location.hostname;
if (host !== "localhost" && host !== "127.0.0.1") {
return PRODUCTION_API_URL;
}
return `${window.location.protocol}//${host}:8000`;
}
return "http://localhost:8000";
}
Expand Down
4 changes: 2 additions & 2 deletions infra/docker/frontend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ WORKDIR /app/frontend

# Build-time args (public env vars baked into the Next.js build).
# These are visible in the browser bundle — never put secrets here.
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_WS_BASE_URL=ws://localhost:8000
ARG NEXT_PUBLIC_API_BASE_URL
ARG NEXT_PUBLIC_WS_BASE_URL
ARG NEXT_PUBLIC_CESIUM_ION_TOKEN

ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
Expand Down