Fix GrampsWeb subpath: patch API/lang/font paths in JS at startup (STI-90)
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy (push) Has been cancelled
Code Quality / quality (push) Has been cancelled

GrampsWeb's frontend JS hardcodes absolute paths like "/api/...",
"/lang/...", "/fonts/..." which bypass <base href>. These now get
rewritten to "/ahnenforschung/api/..." etc. at container startup,
matching both double-quoted and template-literal (backtick) patterns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
SysAdmin Agent
2026-03-24 09:57:29 +00:00
parent 5d27f9235e
commit 3cdf49419e
2 changed files with 42 additions and 4 deletions

View File

@@ -136,11 +136,30 @@ services:
if [ -n "$$GRAMPSWEB_SUBPATH" ] && [ "$$GRAMPSWEB_SUBPATH" != "/" ]; then
SUBPATH="$$GRAMPSWEB_SUBPATH"
case "$$SUBPATH" in */) ;; *) SUBPATH="$${SUBPATH}/" ;; esac
echo "[grampsweb] Patching <base href> to $$SUBPATH ..."
echo "[grampsweb] Patching static files for subpath $$SUBPATH ..."
find / -name index.html -path "*/gramps*" -o -name index.html -path "*/static/*" 2>/dev/null | while read f; do
if grep -q '<base href="/">' "$$f" 2>/dev/null; then
sed -i "s|<base href=\"/\">|<base href=\"$$SUBPATH\">|g" "$$f"
echo "[grampsweb] patched: $$f"
echo "[grampsweb] patched base href: $$f"
fi
done
for f in /app/static/*.js; do
if [ -f "$$f" ] && grep -q '/api/' "$$f" 2>/dev/null; then
sed -i "s|\"/api/|\"$${SUBPATH}api/|g" "$$f"
sed -i 's|`/api/|`'"$${SUBPATH}"'api/|g' "$$f"
sed -i "s|\"/lang/|\"$${SUBPATH}lang/|g" "$$f"
sed -i 's|`/lang/|`'"$${SUBPATH}"'lang/|g' "$$f"
sed -i "s|\"/fonts/|\"$${SUBPATH}fonts/|g" "$$f"
sed -i 's|`/fonts/|`'"$${SUBPATH}"'fonts/|g' "$$f"
sed -i "s|\"/assets/|\"$${SUBPATH}assets/|g" "$$f"
sed -i 's|`/assets/|`'"$${SUBPATH}"'assets/|g' "$$f"
echo "[grampsweb] patched JS paths: $$f"
fi
done
for f in /app/static/*.css; do
if [ -f "$$f" ] && grep -q '"/fonts/' "$$f" 2>/dev/null; then
sed -i "s|\"/fonts/|\"$${SUBPATH}fonts/|g" "$$f"
echo "[grampsweb] patched CSS paths: $$f"
fi
done
echo "[grampsweb] Done."