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