diff --git a/.env.example b/.env.example index 6f0d34b..0b659a3 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,10 @@ # Copy this file to .env.local and fill in your values # API Configuration -NEXT_PUBLIC_API_URL=http://localhost:3100 +# Browser-side requests use relative URLs (empty string) automatically. +# API_INTERNAL_URL is only needed for server-side rendering in Docker. +# For local dev, the default (http://localhost:3000) works out of the box. +# API_INTERNAL_URL=http://localhost:3100 # Application NEXT_PUBLIC_APP_NAME=Barazo diff --git a/src/__tests__/auth/auth-context.test.tsx b/src/__tests__/auth/auth-context.test.tsx index dc3f4f7..6c955ca 100644 --- a/src/__tests__/auth/auth-context.test.tsx +++ b/src/__tests__/auth/auth-context.test.tsx @@ -9,7 +9,7 @@ import { useAuth } from '@/hooks/use-auth' import { http, HttpResponse } from 'msw' import { server } from '@/mocks/server' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' // Test component that exposes auth context values function AuthDisplay() { diff --git a/src/__tests__/auth/auth-fetch.test.ts b/src/__tests__/auth/auth-fetch.test.ts index 4ac6ad2..34ca993 100644 --- a/src/__tests__/auth/auth-fetch.test.ts +++ b/src/__tests__/auth/auth-fetch.test.ts @@ -8,7 +8,7 @@ import { server } from '@/mocks/server' import { createAuthFetch } from '@/lib/api/auth-fetch' import { mockAuthSession } from '@/mocks/data' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' describe('createAuthFetch', () => { let getToken: ReturnType diff --git a/src/__tests__/auth/callback-page.test.tsx b/src/__tests__/auth/callback-page.test.tsx index 1be754e..80cf2b6 100644 --- a/src/__tests__/auth/callback-page.test.tsx +++ b/src/__tests__/auth/callback-page.test.tsx @@ -8,7 +8,7 @@ import { http, HttpResponse } from 'msw' import { server } from '@/mocks/server' import CallbackPage from '@/app/auth/callback/page' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' const mockSetSessionFromCallback = vi.fn() diff --git a/src/hooks/use-onboarding.test.ts b/src/hooks/use-onboarding.test.ts index 33d89d7..bd9a97c 100644 --- a/src/hooks/use-onboarding.test.ts +++ b/src/hooks/use-onboarding.test.ts @@ -28,7 +28,7 @@ vi.mock('@/hooks/use-auth', () => ({ }), })) -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' const mockStorage: Record = {} diff --git a/src/lib/api/auth-fetch.ts b/src/lib/api/auth-fetch.ts index 2a1f11f..ab8c35a 100644 --- a/src/lib/api/auth-fetch.ts +++ b/src/lib/api/auth-fetch.ts @@ -7,7 +7,8 @@ import { refreshSession } from './client' import type { AuthSession } from './types' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = + typeof window !== 'undefined' ? '' : (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') interface AuthFetchOptions { method?: 'GET' | 'POST' | 'PUT' | 'DELETE' diff --git a/src/lib/api/client.test.ts b/src/lib/api/client.test.ts index 69459df..72b937f 100644 --- a/src/lib/api/client.test.ts +++ b/src/lib/api/client.test.ts @@ -4,7 +4,7 @@ import { http, HttpResponse } from 'msw' import { server } from '@/mocks/server' import { mockCategories } from '@/mocks/data' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' describe('API client', () => { describe('getCategories', () => { diff --git a/src/lib/api/client.ts b/src/lib/api/client.ts index 9865da0..735d9e0 100644 --- a/src/lib/api/client.ts +++ b/src/lib/api/client.ts @@ -45,7 +45,8 @@ import type { MyReportsResponse, } from './types' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = + typeof window !== 'undefined' ? '' : (process.env.API_INTERNAL_URL ?? 'http://localhost:3000') interface FetchOptions { headers?: Record diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts index e2c24dc..0133c4a 100644 --- a/src/mocks/handlers.ts +++ b/src/mocks/handlers.ts @@ -29,7 +29,7 @@ import { mockMyReports, } from './data' -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000' +const API_URL = '' export const handlers = [ // --- Auth endpoints ---