mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-27 10:54:14 +02:00
fix(maintainerr): inject ingress base path into UI files for React Router
The upstream Maintainerr builds its Vite/React frontend with a __PATH_PREFIX__ placeholder that gets replaced at runtime by start.sh using the BASE_PATH env var. This sets: - React Router's basename (createBrowserRouter) - API base URL (axios calls) - EventSource URLs - Vite asset prefix Without this replacement, React Router has an empty basename and can't match the ingress URL (/api/hassio_ingress/<token>/), returning "No route matches URL". Fix: Replace __PATH_PREFIX__ in the built UI files with the HA ingress entry before starting the app. Remove nginx sub_filters (no longer needed since the UI files already reference the correct ingress-prefixed URLs). Keep the nginx rewrite rule to strip the prefix on the server side. Agent-Logs-Url: https://github.com/alexbelgium/hassio-addons/sessions/e0751563-06a4-4b4e-a4a7-63b2e5f66f03 Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9c4b381b8e
commit
8631d9213c
@@ -65,6 +65,25 @@ if [ ! -f "$DATA_DIR/.initialized" ]; then
|
||||
fi
|
||||
export DATA_DIR
|
||||
|
||||
# ─── Inject ingress base path into the built UI files ─────────────────────────
|
||||
# The upstream Maintainerr Vite build embeds /__PATH_PREFIX__ as a placeholder
|
||||
# for the base URL. The upstream start.sh replaces it with $BASE_PATH at runtime.
|
||||
# For HA ingress, the base path is the dynamic ingress entry (e.g.
|
||||
# /api/hassio_ingress/<token>). We perform the replacement here so the React
|
||||
# Router basename and all asset/API URLs point through the ingress path.
|
||||
# We intentionally do NOT export BASE_PATH so that the NestJS server keeps its
|
||||
# routes at the root — nginx's rewrite rule strips the ingress prefix on the
|
||||
# server side.
|
||||
ingress_entry="$(bashio::addon.ingress_entry 2>/dev/null || true)"
|
||||
if [ -n "$ingress_entry" ]; then
|
||||
UI_DIST_DIR="/opt/app/apps/server/dist/ui"
|
||||
if [ -d "$UI_DIST_DIR" ]; then
|
||||
echo "[Maintainerr] Setting ingress base path: $ingress_entry"
|
||||
find "$UI_DIST_DIR" -type f -not -path '*/node_modules/*' \
|
||||
-print0 | xargs -0 sed -i "s,/__PATH_PREFIX__,${ingress_entry},g" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# ─── Start Maintainerr as unprivileged node user ─────────────────────────────
|
||||
echo "[Maintainerr] Starting application on port ${UI_PORT:-6246}..."
|
||||
exec gosu node /opt/app/start.sh &
|
||||
|
||||
Reference in New Issue
Block a user