fix(6): resolve static asset serving and proxy header issues

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)
This commit is contained in:
2026-04-22 19:34:32 +03:00
parent 0deef7f601
commit 0881b0ecee
2 changed files with 20 additions and 3 deletions

View File

@@ -16,12 +16,16 @@ https://:8919 {
on_demand
}
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-Frame-Options "SAMEORIGIN"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "strict-origin-when-cross-origin"
}
}
@@ -32,7 +36,12 @@ https://:8918 {
on_demand
}
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"
}

View File

@@ -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}...")