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 <noreply@anthropic.com>
This commit is contained in:
1 parent
21e2b9f646
commit
f59e04f62b
3 files changed
+16
-1
No files matched your search
@@ -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=
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user