feat: add BASE_PATH env var for serving UI from a subpath
When BASE_PATH is set (e.g., /server/), the entrypoint script injects a <base> tag and rewrites asset paths in index.html. React Router reads the basename from the <base> tag. Vite builds with relative paths. Default / for standalone mode (no changes). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
21
ui/docker-entrypoint.sh
Normal file
21
ui/docker-entrypoint.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/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/).
|
||||
# Default: / (standalone mode, no <base> tag needed).
|
||||
|
||||
BASE_PATH="${BASE_PATH:-/}"
|
||||
|
||||
if [ "$BASE_PATH" != "/" ]; then
|
||||
# Ensure BASE_PATH starts and ends with /
|
||||
BASE_PATH=$(echo "$BASE_PATH" | sed 's#/*$#/#; s#^/*#/#')
|
||||
|
||||
INDEX="/usr/share/nginx/html/index.html"
|
||||
# Inject <base> tag after <head> and rewrite absolute asset paths
|
||||
sed -i "s|<head>|<head><base href=\"${BASE_PATH}\">|" "$INDEX"
|
||||
sed -i "s|href=\"/|href=\"${BASE_PATH}|g; s|src=\"/|src=\"${BASE_PATH}|g" "$INDEX"
|
||||
|
||||
echo "BASE_PATH set to ${BASE_PATH} — rewrote index.html"
|
||||
fi
|
||||
|
||||
# Delegate to the default nginx entrypoint (handles envsubst for nginx templates)
|
||||
exec /docker-entrypoint.sh "$@"
|
||||
Reference in New Issue
Block a user