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

View File

@@ -88,8 +88,10 @@ COPY --from=cm6-build /build/dist/ /usr/share/nginx/html/vendor/codemirror/
# Builtin extensions (seeded into DB on startup by backend) # Builtin extensions (seeded into DB on startup by backend)
COPY extensions/builtin/ /app/extensions/builtin/ COPY extensions/builtin/ /app/extensions/builtin/
# nginx config # nginx config (template — envsubst injects BASE_PATH at runtime)
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf.template /etc/nginx/templates/default.conf.template
# Only substitute BASE_PATH — preserve nginx variables ($host, $uri, etc.)
ENV NGINX_ENVSUBST_FILTER="BASE_PATH"
# Entrypoint: start Go backend, then nginx # Entrypoint: start Go backend, then nginx
COPY docker-entrypoint.sh /docker-entrypoint.d/90-start-backend.sh COPY docker-entrypoint.sh /docker-entrypoint.d/90-start-backend.sh

View File

@@ -9,6 +9,17 @@
set -e set -e
# Inject BASE_PATH into frontend HTML/JS at runtime
if [ -n "${BASE_PATH}" ]; then
echo "🔧 Injecting BASE_PATH=${BASE_PATH} into frontend assets..."
find /usr/share/nginx/html -type f \( -name '*.html' -o -name '*.js' \) \
-exec sed -i "s|%%BASE_PATH%%|${BASE_PATH}|g" {} +
else
# No prefix — strip the placeholder entirely
find /usr/share/nginx/html -type f \( -name '*.html' -o -name '*.js' \) \
-exec sed -i "s|%%BASE_PATH%%||g" {} +
fi
echo "🔀 Starting Switchboard Core backend..." echo "🔀 Starting Switchboard Core backend..."
# Launch Go backend in background (from /app so migrations are found) # Launch Go backend in background (from /app so migrations are found)

View File

@@ -24,7 +24,7 @@ server {
} }
# ── API + WebSocket → backend ──────────── # ── API + WebSocket → backend ────────────
location ^~ /api/ { location ^~ ${BASE_PATH}/api/ {
proxy_pass $backend; proxy_pass $backend;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
@@ -33,15 +33,15 @@ server {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
location = /health { location = ${BASE_PATH}/health {
proxy_pass $backend; proxy_pass $backend;
} }
location = /metrics { location = ${BASE_PATH}/metrics {
proxy_pass $backend; proxy_pass $backend;
} }
location = /ws { location = ${BASE_PATH}/ws {
proxy_pass $backend; proxy_pass $backend;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
@@ -53,8 +53,8 @@ server {
proxy_send_timeout 86400s; proxy_send_timeout 86400s;
} }
# ── Page routes → backend (Go templates) ─ # ── Page routes → backend (Go renders HTML) ─
location = / { location = ${BASE_PATH}/ {
proxy_pass $backend; proxy_pass $backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@@ -62,19 +62,19 @@ server {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
location = /login { location = ${BASE_PATH}/login {
proxy_pass $backend; proxy_pass $backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
} }
location /admin { 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 /team-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 /settings { 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 /w/ { 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; }
# v0.27.0: Extension surface page routes → backend (Go templates) # Extension surface page routes → backend
location /s/ { location ${BASE_PATH}/s/ {
proxy_pass $backend; proxy_pass $backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@@ -82,18 +82,16 @@ server {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
# v0.27.0: Extension surface static assets (JS, CSS, images) # Extension surface static assets
# v0.28.7: On-disk path moved to /data/packages/, URL retained for stability. location ^~ ${BASE_PATH}/surfaces/ {
# v0.29.2: ^~ prefix beats regex; corrected alias to /data/storage/packages/.
location ^~ /surfaces/ {
alias /data/storage/packages/; alias /data/storage/packages/;
expires off; expires off;
add_header Cache-Control "no-cache"; add_header Cache-Control "no-cache";
} }
# Fallback: redirect unknown paths to root # Fallback: serve frontend shell (SPA)
location / { location ${BASE_PATH}/ {
try_files $uri $uri/ /index.html; try_files $uri $uri/ ${BASE_PATH}/index.html;
} }
# Security headers # Security headers