Compare commits

...

4 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
f622ff9925 fix(maintainerr): filter file types in PATH_PREFIX replacement to skip binaries
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>
2026-04-03 14:03:52 +00:00
copilot-swe-agent[bot]
8631d9213c 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>
2026-04-03 14:02:46 +00:00
copilot-swe-agent[bot]
9c4b381b8e fix(maintainerr): add warning when bashio library is not found
Agent-Logs-Url: https://github.com/alexbelgium/hassio-addons/sessions/d5bff0a8-62ba-4564-a4fc-74c87d8b0d55

Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
2026-04-03 13:07:30 +00:00
copilot-swe-agent[bot]
464c7362d8 fix(maintainerr): fix broken init script execution causing ingress 404
The entrypoint used `bashio "$script"` to run init scripts, but bashio CLI
is a function dispatcher (bashio::"${@}"), not a script interpreter. This
meant 32-nginx_ingress.sh never executed, leaving nginx config with
unsubstituted %%port%%/%%interface%%/%%ingress_entry%% placeholders, so
nginx failed to start and ingress returned 404.

Fix: source the bashio library first, then run each init script via
`source` in a subshell so bashio:: functions are inherited.

Agent-Logs-Url: https://github.com/alexbelgium/hassio-addons/sessions/d5bff0a8-62ba-4564-a4fc-74c87d8b0d55

Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
2026-04-03 13:06:45 +00:00
2 changed files with 38 additions and 30 deletions

View File

@@ -7,7 +7,6 @@ server {
gzip_static off;
client_max_body_size 0;
# Based on https://docs.maintainerr.info/ReverseProxy/#nginx-subdomain
location / {
set $app '%%ingress_entry%%';
@@ -23,7 +22,6 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_read_timeout 90;
add_header X-Frame-Options "SAMEORIGIN";
add_header 'Referrer-Policy' 'no-referrer';
@@ -31,31 +29,5 @@ server {
# Redirect location headers
absolute_redirect off;
proxy_redirect / $app/;
# Sub filters to rewrite URLs in responses
sub_filter_once off;
sub_filter_types *;
# HTML attribute rewrites
sub_filter 'href="/"' 'href="%%ingress_entry%%/"';
sub_filter 'src="/' 'src="%%ingress_entry%%/';
sub_filter 'action="/' 'action="%%ingress_entry%%/';
# API path rewrites
sub_filter '"/api' '"%%ingress_entry%%/api';
sub_filter '`/api' '`%%ingress_entry%%/api';
sub_filter "'/api" "'%%ingress_entry%%/api";
# Vite asset rewrites
sub_filter '"/assets' '"%%ingress_entry%%/assets';
sub_filter '`/assets' '`%%ingress_entry%%/assets';
sub_filter "'/assets" "'%%ingress_entry%%/assets";
# Favicon and static files
sub_filter '"/favicon' '"%%ingress_entry%%/favicon';
sub_filter '"/logo' '"%%ingress_entry%%/logo';
# Root path references in JavaScript
sub_filter '"\/"' '"%%ingress_entry%%\/"';
}
}

View File

@@ -7,13 +7,28 @@ set -e
# Runs cont-init.d scripts then drops privileges and starts the app.
###############################################################################
# ─── Source bashio library so init scripts can use bashio:: functions ─────────
_bashio_loaded=false
for _f in /usr/lib/bashio/bashio /usr/lib/bashio/bashio.sh; do
if [ -f "$_f" ]; then
# shellcheck disable=SC1090
source "$_f"
_bashio_loaded=true
break
fi
done
if [ "$_bashio_loaded" = false ]; then
echo "[Maintainerr] WARNING: bashio library not found; init scripts using bashio functions will fail"
fi
# ─── Run cont-init.d scripts ─────────────────────────────────────────────────
if [ -d /etc/cont-init.d ]; then
for script in /etc/cont-init.d/*.sh; do
[ -f "$script" ] || continue
sed -i '1s|.*|#!/usr/bin/env bashio|' "$script"
echo "[Maintainerr] Running init script: $script"
bashio "$script"
# Run in subshell to isolate side effects; bashio functions are inherited
# shellcheck disable=SC1090
( source "$script" )
done
fi
@@ -50,6 +65,27 @@ 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"
# Only process text-based web files (skip binary assets like images/fonts)
find "$UI_DIST_DIR" -type f \( -name '*.js' -o -name '*.mjs' -o -name '*.html' -o -name '*.css' -o -name '*.json' -o -name '*.map' \) \
-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 &