From f59e04f62b8c1e533b03f4f1297e9ed90f25aa56 Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Sun, 19 Jul 2026 17:51:32 +0200 Subject: [PATCH] Next.js Dev-Server: allowedDevOrigins fuer LAN-Zugriff (NAS-Deployment) Beim Testen auf einem NAS per LAN-IP statt localhost blockierte Next.js' Dev-Server standardmaessig die HMR-Websocket-Verbindung von der fremden IP - im Turbopack-Dev-Modus haengt dadurch die Hydration komplett, die Seite bleibt bei der server-gerenderten "Laedt..."-HTML stehen und kein Client-JS (damit auch kein API-Fetch) laeuft je. Fix: konfigurierbare allowedDevOrigins ueber die neue NEXT_DEV_ALLOWED_ORIGINS-Env-Var. Co-Authored-By: Claude Sonnet 5 --- pflegepilot_v3/.env.example | 5 +++++ pflegepilot_v3/docker-compose.yml | 1 + pflegepilot_v3/frontend/next.config.ts | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pflegepilot_v3/.env.example b/pflegepilot_v3/.env.example index 24c6258..95f9942 100644 --- a/pflegepilot_v3/.env.example +++ b/pflegepilot_v3/.env.example @@ -16,3 +16,8 @@ WEB_ORIGIN=http://localhost:3100 # --- Frontend (Next.js) --- WEB_PORT=3100 NEXT_PUBLIC_API_URL=http://localhost:8100 +# Nur noetig, wenn per LAN-IP/Hostname statt localhost zugegriffen wird +# (z.B. Deployment auf einem NAS) - sonst blockt Next.js im Dev-Modus die +# HMR-Verbindung und die App haengt bei "Laedt...". Kommagetrennt bei +# mehreren Hosts/IPs. Beispiel: NEXT_DEV_ALLOWED_ORIGINS=192.168.1.222 +NEXT_DEV_ALLOWED_ORIGINS= diff --git a/pflegepilot_v3/docker-compose.yml b/pflegepilot_v3/docker-compose.yml index c7a1718..51a7f41 100644 --- a/pflegepilot_v3/docker-compose.yml +++ b/pflegepilot_v3/docker-compose.yml @@ -38,6 +38,7 @@ services: build: ./frontend environment: NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL} + NEXT_DEV_ALLOWED_ORIGINS: ${NEXT_DEV_ALLOWED_ORIGINS:-} ports: - "${WEB_PORT:-3100}:3000" volumes: diff --git a/pflegepilot_v3/frontend/next.config.ts b/pflegepilot_v3/frontend/next.config.ts index e9ffa30..9ba03cf 100644 --- a/pflegepilot_v3/frontend/next.config.ts +++ b/pflegepilot_v3/frontend/next.config.ts @@ -1,7 +1,16 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + // Next.js' Dev-Server blockt standardmaessig Cross-Origin-Zugriffe auf + // interne Dev-Ressourcen (HMR-Websocket) von anderen Hosts als localhost. + // Noetig, sobald per LAN-IP statt localhost zugegriffen wird (z.B. Deployment + // auf einem NAS, Zugriff von einem anderen Geraet im selben Netz) - ohne das + // haengt die HMR-Verbindung, was im Turbopack-Dev-Modus die Hydration + // blockiert (Seite bleibt bei der server-gerenderten "Laedt..."-HTML stehen). + // Betrifft nur den Dev-Server, nicht den Produktions-Build aus Phase 7. + allowedDevOrigins: process.env.NEXT_DEV_ALLOWED_ORIGINS + ? process.env.NEXT_DEV_ALLOWED_ORIGINS.split(",") + : undefined, }; export default nextConfig;