Refactor GrampsWeb subpath handling: move all patching to nginx sub_filter (STI-98)
Replace fragile container-side sed/JS patching with comprehensive nginx sub_filter rules. The container now only handles admin user creation on startup. All SPA route prefixing is done in nginx via a History API interceptor injected into HTML responses. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
44
compose.yml
44
compose.yml
@@ -197,56 +197,16 @@ services:
|
||||
- GRAMPSWEB_ADMIN_EMAIL=${GRAMPSWEB_ADMIN_EMAIL:-admin@localhost}
|
||||
- GRAMPSWEB_ADMIN_PASSWORD=${GRAMPSWEB_ADMIN_PASSWORD:-gramps_dev_password}
|
||||
- GRAMPSWEB_TREE=${GRAMPSWEB_TREE:-Stiftung}
|
||||
- GRAMPSWEB_BASE_URL=${GRAMPSWEB_BASE_URL:-http://localhost:8090}
|
||||
- GRAMPSWEB_BASE_URL=${GRAMPSWEB_BASE_URL:-https://vhtv-stiftung.de/ahnenforschung}
|
||||
- GRAMPSWEB_CELERY_CONFIG__broker_url=redis://redis:6379/0
|
||||
- GRAMPSWEB_CELERY_CONFIG__result_backend=redis://redis:6379/0
|
||||
- GRAMPSWEB_RATELIMIT_STORAGE_URI=redis://redis:6379/1
|
||||
- GRAMPSWEB_NEW_DB_BACKEND=sqlite
|
||||
- GRAMPSWEB_SUBPATH=${GRAMPSWEB_SUBPATH:-/ahnenforschung}
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
if [ -n "$$GRAMPSWEB_SUBPATH" ] && [ "$$GRAMPSWEB_SUBPATH" != "/" ]; then
|
||||
SUBPATH="$$GRAMPSWEB_SUBPATH"
|
||||
case "$$SUBPATH" in */) ;; *) SUBPATH="$${SUBPATH}/" ;; esac
|
||||
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 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"
|
||||
sed -i "s|location\.href=\"/\"|location.href=\"$$SUBPATH\"|g" "$$f"
|
||||
sed -i "s|document\.location\.href=\"/\"|document.location.href=\"$$SUBPATH\"|g" "$$f"
|
||||
echo "[grampsweb] patched JS paths: $$f"
|
||||
fi
|
||||
done
|
||||
if [ -f /app/static/sw.js ]; then
|
||||
sed -i "s|createHandlerBoundToURL(\"/index.html\")|createHandlerBoundToURL(\"$${SUBPATH}index.html\")|g" /app/static/sw.js
|
||||
SUBPATH_BS=$$(echo "$$SUBPATH" | sed "s|/|\\\\\\\\/|g")
|
||||
sed -i "s|\\^\\\\/api|\\^$${SUBPATH_BS}api|g" /app/static/sw.js
|
||||
echo "[grampsweb] patched sw.js navigation routes"
|
||||
fi
|
||||
find /app/static -name '*.css' 2>/dev/null | while read f; do
|
||||
if grep -q '\.\./fonts/' "$$f" 2>/dev/null; then
|
||||
sed -i "s|'../fonts/|'fonts/|g" "$$f"
|
||||
sed -i "s|\"../fonts/|\"fonts/|g" "$$f"
|
||||
echo "[grampsweb] patched CSS font paths: $$f"
|
||||
fi
|
||||
done
|
||||
echo "[grampsweb] Done."
|
||||
fi
|
||||
# All subpath rewriting is handled by nginx sub_filter — no container patching needed.
|
||||
echo "[grampsweb] Ensuring admin user exists ..."
|
||||
python3 << 'PYEOF' 2>&1 | grep -v Gtk
|
||||
from gramps_webapi.app import create_app
|
||||
|
||||
Reference in New Issue
Block a user