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
2 changes: 0 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VITE_API_URL=http://192.168.60.54
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY packages/room-client/package.json packages/room-client/package.json
FROM base AS build

# VITE_API_URL is baked into the client JS bundle at build time
ARG VITE_API_URL=http://localhost:5175
ARG VITE_API_URL=
ENV VITE_API_URL=${VITE_API_URL}

RUN pnpm install --frozen-lockfile
Expand Down
25 changes: 21 additions & 4 deletions apps/web/src/lib/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,36 @@
* Resolution order:
* 1. VITE_API_URL (baked at build time by Vite, available via import.meta.env in browser)
* 2. process.env.VITE_API_URL (available during SSR / Nitro)
* 3. Fallback to localhost:5175 (local dev)
* 3. window.location.origin (browser same-origin — works behind reverse proxy)
* 4. Fallback to localhost:5175 (local dev without env, SSR without env)
*/

function resolveApiUrl(): string {
// Browser / Vite client bundle
if (typeof import.meta.env?.VITE_API_URL === "string") {
return import.meta.env.VITE_API_URL;
// Explicit override via env var (local dev, split deployments)
const envUrl = import.meta.env?.VITE_API_URL;
if (typeof envUrl === "string" && envUrl.length > 0) {
console.info("[endpoints] API_URL from VITE_API_URL:", envUrl);
return envUrl;
}
// SSR (Nitro) — process.env is available
// biome-ignore lint/complexity/useOptionalChain: typeof guard needed for undeclared global
if (typeof process !== "undefined" && process.env?.VITE_API_URL) {
console.info(
"[endpoints] API_URL from process.env:",
process.env.VITE_API_URL,
);
return process.env.VITE_API_URL;
}
// Browser: same-origin (API served from same host via reverse proxy)
if (typeof window !== "undefined") {
console.info(
"[endpoints] API_URL from window.location.origin:",
window.location.origin,
);
return window.location.origin;
}
// Final fallback (local dev without env, SSR without env)
console.warn("[endpoints] API_URL falling back to http://localhost:5175");
return "http://localhost:5175";
}

Expand Down