fix BASE_PATH routing: nginx template + runtime HTML injection
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m16s
CI/CD / test-sqlite (push) Successful in 2m31s
CI/CD / build-and-deploy (push) Successful in 33s

- nginx.conf → nginx.conf.template with ${BASE_PATH} in all locations
- NGINX_ENVSUBST_FILTER=BASE_PATH so nginx vars ($host, $uri) are preserved
- Entrypoint injects BASE_PATH into frontend HTML/JS (%%BASE_PATH%% → actual)
- Fixes: /test routes falling through to static SPA, %%BASE_PATH%% visible in URL

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 13:23:41 +00:00
parent d32fa5f92d
commit 10cfd147fe
3 changed files with 33 additions and 22 deletions

101
nginx.conf.template Normal file
View File

@@ -0,0 +1,101 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Backend upstream (unified container: localhost:8080)
set $backend http://127.0.0.1:8080;
# Gzip
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
# Static assets — images/fonts get long cache; JS/CSS use revalidation
location ~* \.(jpg|jpeg|png|gif|ico|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
location ~* \.(css|js)$ {
add_header Cache-Control "no-cache, must-revalidate";
}
# ── API + WebSocket → backend ────────────
location ^~ ${BASE_PATH}/api/ {
proxy_pass $backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location = ${BASE_PATH}/health {
proxy_pass $backend;
}
location = ${BASE_PATH}/metrics {
proxy_pass $backend;
}
location = ${BASE_PATH}/ws {
proxy_pass $backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
# ── Page routes → backend (Go renders HTML) ─
location = ${BASE_PATH}/ {
proxy_pass $backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location = ${BASE_PATH}/login {
proxy_pass $backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ${BASE_PATH}/admin { proxy_pass $backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
location ${BASE_PATH}/team-admin { proxy_pass $backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
location ${BASE_PATH}/settings { proxy_pass $backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
location ${BASE_PATH}/w/ { proxy_pass $backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
# Extension surface page routes → backend
location ${BASE_PATH}/s/ {
proxy_pass $backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Extension surface static assets
location ^~ ${BASE_PATH}/surfaces/ {
alias /data/storage/packages/;
expires off;
add_header Cache-Control "no-cache";
}
# Fallback: serve frontend shell (SPA)
location ${BASE_PATH}/ {
try_files $uri $uri/ ${BASE_PATH}/index.html;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}