From 23227a16a5e1a6a17c2ae411126a337842fe30c4 Mon Sep 17 00:00:00 2001 From: Trezy Date: Thu, 7 May 2026 16:18:17 -0500 Subject: [PATCH] fix: update the base path rewrite to skip Nexts basePath config --- Dockerfile | 5 ++++- entrypoint.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 96d2f5d..87aee8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ WORKDIR /app/web COPY web/package.json web/package-lock.json ./ RUN npm ci COPY web/ . +ENV NEXT_PUBLIC_BASE_PATH=/__HAPPYVIEW_BP__ RUN npm run build FROM rust:1.93-bookworm AS builder @@ -34,9 +35,11 @@ WORKDIR /app COPY --from=builder /app/target/release/happyview /usr/local/bin/happyview COPY --from=builder /app/migrations /app/migrations COPY --from=frontend /app/web/out /srv/static +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh && touch /srv/static/.base-path-pending ENV STATIC_DIR=/srv/static EXPOSE 3000 -ENTRYPOINT ["happyview"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..ef23dd4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -e + +BP="${BASE_PATH:-}" +STATIC="${STATIC_DIR:-/srv/static}" +SENTINEL="/__HAPPYVIEW_BP__" +MARKER="${STATIC}/.base-path-pending" + +# Only run replacement once (marker is created during Docker build) +if [ -f "$MARKER" ]; then + if [ -n "$BP" ]; then + # Validate: must start with / + case "$BP" in + /*) ;; + *) echo "ERROR: BASE_PATH must start with '/' (got: $BP)" >&2; exit 1 ;; + esac + # Strip trailing slash + BP="${BP%/}" + + # Replace sentinel string in static files with actual base path + find "${STATIC}" -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' \) \ + -exec sed -i "s|${SENTINEL}|${BP}|g" {} + + else + # No base path: remove sentinel string from static files + find "${STATIC}" -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' \) \ + -exec sed -i "s|${SENTINEL}||g" {} + + fi + + rm "$MARKER" +fi + +exec happyview "$@" -- 2.51.2