#!/bin/sh
# Patched entrypoint: fixes the sed ordering bug in the server-ui image.
# The original entrypoint inserts then rewrites ALL href="/..."
# including the just-inserted base tag, causing /server/server/ doubling.
BASE_PATH="${BASE_PATH:-/}"
if [ "$BASE_PATH" != "/" ]; then
BASE_PATH=$(echo "$BASE_PATH" | sed 's#/*$#/#; s#^/*#/#')
INDEX="/usr/share/nginx/html/index.html"
# Rewrite absolute asset paths FIRST (before inserting )
sed -i "s|href=\"/|href=\"${BASE_PATH}|g; s|src=\"/|src=\"${BASE_PATH}|g" "$INDEX"
# THEN inject tag
sed -i "s|
||" "$INDEX"
echo "BASE_PATH set to ${BASE_PATH} — rewrote index.html"
fi
exec /docker-entrypoint.sh "$@"