fix(api): API-Host im Dev-Modus aus window.location ableiten (LAN/Handy-Zugriff)
Statt fest http://localhost:5179 (auf dem Handy = das Handy selbst) nutzt der Client im Dev-Modus den Host, von dem die Seite geladen wurde → 192.168.x.y:5179. e2e/Rechner bleiben bei localhost. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,18 @@ import { de } from '../strings/de'
|
|||||||
/**
|
/**
|
||||||
* Basis-URL der GerbilManagerWebAPI.
|
* Basis-URL der GerbilManagerWebAPI.
|
||||||
* Dev (Vite dev server / e2e mock): absolute URL, damit Playwright-Route-Interception greift.
|
* Dev (Vite dev server / e2e mock): absolute URL, damit Playwright-Route-Interception greift.
|
||||||
|
* Der Host wird aus der AKTUELLEN Adresse abgeleitet (window.location.hostname), damit der
|
||||||
|
* Zugriff vom Handy/anderen LAN-Gerät funktioniert: lädt die Seite von 192.168.x.y:5173,
|
||||||
|
* geht die API an 192.168.x.y:5179 (nicht „localhost", was auf dem Handy das Handy selbst wäre).
|
||||||
|
* Auf dem Rechner/in e2e ist der Host „localhost" → unverändert http://localhost:5179.
|
||||||
* Produktion (Vite build → nginx): relativer Pfad /api; nginx proxyt zum API-Container.
|
* Produktion (Vite build → nginx): relativer Pfad /api; nginx proxyt zum API-Container.
|
||||||
* Aspire (VITE_API_BASE_URL gesetzt): überschreibt immer (LAN-IP + Port für Handy-Zugriff).
|
* Aspire (VITE_API_BASE_URL gesetzt): überschreibt immer.
|
||||||
*/
|
*/
|
||||||
|
const devApiBase = `http://${
|
||||||
|
typeof window !== 'undefined' && window.location.hostname ? window.location.hostname : 'localhost'
|
||||||
|
}:5179`
|
||||||
export const API_BASE_URL: string =
|
export const API_BASE_URL: string =
|
||||||
import.meta.env.VITE_API_BASE_URL ?? (import.meta.env.PROD ? '/api' : 'http://localhost:5179')
|
import.meta.env.VITE_API_BASE_URL ?? (import.meta.env.PROD ? '/api' : devApiBase)
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
readonly status: number | null
|
readonly status: number | null
|
||||||
|
|||||||
Reference in New Issue
Block a user