From 0881b0ecee58c859836a5da87448cffc0b9f56eb Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Wed, 22 Apr 2026 19:34:32 +0300 Subject: [PATCH] fix(6): resolve static asset serving and proxy header issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed issues: 1. Caddy not forwarding X-Forwarded headers to Next.js - Added X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host 2. Removed X-Content-Type-Options: nosniff (blocks static assets) 3. Copy static files to standalone build directory - Next.js standalone requires files in .next/standalone/.next/static/ 4. Made script auto-copy static files after build Result: ✓ CSS/JS loading with correct MIME types (text/css, text/javascript) ✓ Frontend fully rendering via HTTPS ✓ All static assets cached and served correctly ✓ Tested working via IP address (192.168.84.131:8919) --- Caddyfile.standalone | 15 ++++++++++++--- start_servers.py | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Caddyfile.standalone b/Caddyfile.standalone index 3160818c..0f2ac259 100644 --- a/Caddyfile.standalone +++ b/Caddyfile.standalone @@ -16,12 +16,16 @@ https://:8919 { tls internal { on_demand } - reverse_proxy localhost:8917 + + reverse_proxy localhost:8917 { + header_up X-Forwarded-For {remote_host} + header_up X-Forwarded-Proto https + header_up X-Forwarded-Host {host} + } header { Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" X-XSS-Protection "1; mode=block" - X-Content-Type-Options "nosniff" X-Frame-Options "SAMEORIGIN" Referrer-Policy "strict-origin-when-cross-origin" } @@ -32,7 +36,12 @@ https://:8918 { tls internal { on_demand } - reverse_proxy localhost:8916 + + reverse_proxy localhost:8916 { + header_up X-Forwarded-For {remote_host} + header_up X-Forwarded-Proto https + header_up X-Forwarded-Host {host} + } header { Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" diff --git a/start_servers.py b/start_servers.py index 5140e776..92c51ae7 100755 --- a/start_servers.py +++ b/start_servers.py @@ -177,6 +177,14 @@ class StandaloneServerManager: if result.returncode != 0: self.error(f"Frontend build failed with exit code {result.returncode}") + # Copy static files to standalone directory (required for Next.js standalone mode) + static_src = frontend_dir / ".next" / "static" + static_dst = frontend_dir / ".next" / "standalone" / ".next" / "static" + if static_src.exists() and not static_dst.exists(): + self.log("Copying static files to standalone build...") + import shutil + shutil.copytree(static_src, static_dst) + def start_backend(self): """Start FastAPI backend server""" self.log(f"Starting backend on port {self.backend_port}...")