fix: use relative asset paths with always-injected <base> tag
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m22s
CI / docker (push) Successful in 1m11s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 43s

Switch Vite base back to './' (relative paths) and always inject
<base href="${BASE_PATH}"> in the entrypoint, even when BASE_PATH=/.

This fixes asset loading for both deployment modes:
- Single-instance: <base href="/"> resolves ./assets/x.js to /assets/x.js
- SaaS tenant: <base href="/t/slug/"> resolves to /t/slug/assets/x.js

Previously base:'/' produced absolute /assets/ paths that the <base>
tag couldn't redirect, breaking SaaS tenants. And base:'./' without
<base> broke deep URLs in single-instance mode. Always injecting the
tag makes relative paths work universally.

The patched server-ui-entrypoint.sh in cameleer-saas (which rewrote
absolute href/src attributes via sed) is no longer needed and can be
removed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-13 21:30:00 +02:00
parent 67e2c1a531
commit fe283674fb
2 changed files with 11 additions and 13 deletions

View File

@@ -1,21 +1,19 @@
#!/bin/sh
# Inject <base> tag into index.html when BASE_PATH is set.
# This allows the SPA to be served from a subpath (e.g., /server/).
# Vite builds with base: './' (relative paths), so the <base> tag
# is sufficient — no asset path rewriting needed.
# Default: / (standalone mode, no <base> tag needed).
# Inject <base> tag into index.html so relative asset paths (./assets/...)
# resolve correctly regardless of the browser URL depth or subpath mount.
# Vite builds with base: './' (relative paths), so <base> is the only
# mechanism needed — no sed rewriting of asset paths required.
# Default: / (standalone mode).
BASE_PATH="${BASE_PATH:-/}"
if [ "$BASE_PATH" != "/" ]; then
# Ensure BASE_PATH starts and ends with /
BASE_PATH=$(echo "$BASE_PATH" | sed 's#/*$#/#; s#^/*#/#')
# Ensure BASE_PATH starts and ends with /
BASE_PATH=$(echo "$BASE_PATH" | sed 's#/*$#/#; s#^/*#/#')
INDEX="/usr/share/nginx/html/index.html"
sed -i "s|<head>|<head><base href=\"${BASE_PATH}\">|" "$INDEX"
INDEX="/usr/share/nginx/html/index.html"
sed -i "s|<head>|<head><base href=\"${BASE_PATH}\">|" "$INDEX"
echo "BASE_PATH set to ${BASE_PATH} — injected <base> tag into index.html"
fi
echo "BASE_PATH set to ${BASE_PATH} — injected <base> tag into index.html"
# Delegate to the default nginx entrypoint (handles envsubst for nginx templates)
exec /docker-entrypoint.sh "$@"

View File

@@ -27,7 +27,7 @@ export default defineConfig({
optimizeDeps: {
include: ['swagger-ui-dist/swagger-ui-bundle'],
},
base: '/',
base: './',
build: {
outDir: 'dist',
},