Barazo default frontend barazo.forum

fix(api): remove NEXT_PUBLIC_API_URL to prevent localhost fallback in client bundle (#88)

Turbopack was not dead-code-eliminating the typeof window ternary
correctly, causing the server-side fallback (http://localhost:3000)
to leak into the client bundle. The browser then made cross-origin
requests to localhost instead of same-origin relative URLs, producing
"NetworkError when attempting to fetch resource" on staging.

Replace the fragile process.env pattern with a simple literal: client
always uses '' (relative URLs via Caddy), server uses API_INTERNAL_URL.

authored by

Guido X Jansen and committed by
GitHub
a0be5880 b02cc418

+4 -6
+2 -3
src/lib/api/auth-fetch.ts
··· 7 7 import { refreshSession } from './client' 8 8 import type { AuthSession } from './types' 9 9 10 + /** Client: relative URLs (empty string). Server: internal Docker network URL. */ 10 11 const API_URL = 11 - typeof window !== 'undefined' 12 - ? (process.env.NEXT_PUBLIC_API_URL ?? '') 13 - : (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') 12 + typeof window === 'undefined' ? (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') : '' 14 13 15 14 interface AuthFetchOptions { 16 15 method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
+2 -3
src/lib/api/client.ts
··· 60 60 BehavioralFlag, 61 61 } from './types' 62 62 63 + /** Client: relative URLs (empty string). Server: internal Docker network URL. */ 63 64 const API_URL = 64 - typeof window !== 'undefined' 65 - ? (process.env.NEXT_PUBLIC_API_URL ?? '') 66 - : (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') 65 + typeof window === 'undefined' ? (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') : '' 67 66 68 67 interface FetchOptions { 69 68 headers?: Record<string, string>