The app's assets were already relative — the shell loads fine from any directory, which is how
the demo lives under /demo/. What assumed the site root was the API call: `fetch('/api/...')`
went to the proxy's own root, where there is nothing to answer it, so behind
`https://example.com/gym/` the app booted and then could not talk to its server.
It now asks its own address instead: `appBase()` reads the directory the app is being served
from, which the router never leaves — every screen is a hash, and a path that is not a file is
sent back to the app's root before React boots. A proxy that strips its prefix (Caddy's
`handle_path`, Traefik's StripPrefix) therefore needs no configuration at all.
For a proxy that passes the prefix through, the web container takes `BASE_PATH=/gym`, rendered
into its nginx config at start-up like the other settings, so it applies to a prebuilt image.
Wired through docker-compose.yml as well — a documented setting the compose file does not pass
on is no setting at all.
Both shapes were checked in containers rather than read: with BASE_PATH empty the shell, the
assets, /api and the deep-path redirect behave exactly as before; with BASE_PATH=/gym all four
work under the prefix and the redirect stays inside it. The first attempt passed at /gym/ and
404'd /gym/assets/app.js, because a regex location outranks the prefix block and never saw its
rewrite — the cache-control blocks carry it too now. The built app was then loaded in a browser
under /gym/ and its own requests go to /gym/api/config and /gym/api/me.
Reported by leon332157.
75 lines
4.2 KiB
Docker
75 lines
4.2 KiB
Docker
# Multi-stage: build the React app, then serve it with nginx.
|
|
# Self-hosters never need Node locally — `docker compose up` builds everything.
|
|
#
|
|
# --platform=$BUILDPLATFORM pins the build stage to the host's native arch even when
|
|
# cross-building for other targets (e.g. amd64 host building an arm64 image). The build
|
|
# output (static JS/CSS/HTML) is arch-independent, so there's no reason to run it under
|
|
# QEMU — and QEMU-emulated npm installs are known to corrupt esbuild/rollup's platform-
|
|
# specific native binaries, which is what breaks `vite build` with unrelated-looking
|
|
# module-resolution errors.
|
|
FROM --platform=$BUILDPLATFORM node:22-alpine AS build
|
|
# The frontend sits at /app/frontend, not /app: the Coach's runtime-neutral core lives in
|
|
# api/coach/core and is imported from frontend/src as ../../../api/coach/core/*, so the two
|
|
# have to keep the same relative position they have in the repository. Copying frontend/ alone
|
|
# is exactly what made the v1.2.15 web image fail to build.
|
|
WORKDIR /app/frontend
|
|
COPY frontend/package.json frontend/package-lock.json* ./
|
|
# --ignore-scripts: the web image only needs `vite build`; the one heavy postinstall in this tree
|
|
# (@capacitor/assets -> sharp, a libvips download from GitHub) is for drawing app icons and has
|
|
# timed out on the shared runners — a lockfile-ignoring `npm install` fallback is no answer to that.
|
|
RUN npm ci --ignore-scripts
|
|
COPY api/coach/core/ /app/api/coach/core/
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
FROM nginx:alpine
|
|
# Same reason as in api/Dockerfile: alpine fixes land faster than the nginx image is rebuilt.
|
|
RUN apk upgrade --no-cache
|
|
ARG VERSION=dev
|
|
ARG VCS_REF=dev
|
|
ARG BUILD_DATE=unknown
|
|
|
|
LABEL maintainer="Duarte Santos https://gitlab.com/DuarteSantos8" \
|
|
org.opencontainers.image.title="opengym-web" \
|
|
org.opencontainers.image.description="Frontend for Self-hosted gym & body-weight tracker — plan routines, log workouts (supersets & cardio too), track your weight and progress, passkey login. Your data, your server." \
|
|
org.opencontainers.image.source="https://gitlab.com/DuarteSantos8/opengym" \
|
|
org.opencontainers.image.url="https://gitlab.com/DuarteSantos8/opengym/container_registry" \
|
|
org.opencontainers.image.documentation="https://gitlab.com/DuarteSantos8/opengym#readme" \
|
|
org.opencontainers.image.licenses="AGPL-3.0-or-later" \
|
|
org.opencontainers.image.version=$VERSION \
|
|
org.opencontainers.image.revision=$VCS_REF \
|
|
org.opencontainers.image.created=$BUILD_DATE
|
|
|
|
COPY web/nginx.conf.template /etc/nginx/templates/default.conf.template
|
|
COPY --from=build /app/frontend/dist /usr/share/nginx/html
|
|
# exercise media (img/gif) is mounted at runtime from the media volume
|
|
|
|
# Set Default ENVs for nginx
|
|
ENV NGINX_PORT=80
|
|
ENV BACKEND=api
|
|
ENV PORT=3000
|
|
# The DNS nginx asks about BACKEND on every /api request. Docker's embedded resolver by
|
|
# default, which is correct for compose. Nothing listens on it elsewhere, and an unreachable
|
|
# resolver makes every /api request hang rather than fail, so any other runtime has to say
|
|
# what its DNS is: on Kubernetes, the kube-dns/CoreDNS service address (commonly 10.96.0.10).
|
|
ENV RESOLVER=127.0.0.11
|
|
# Empty = the CF-Connecting-IP header is dropped before it reaches the API, so it cannot be
|
|
# forged by a direct client. Set to $http_cf_connecting_ip only when Cloudflare is really in
|
|
# front. Defined here too, not just in compose, so the template always renders for anyone
|
|
# running the prebuilt image from their own compose file.
|
|
ENV CF_CONNECTING_IP=""
|
|
# Subpath deployments behind a reverse proxy that does NOT strip its prefix: "/gym", no trailing
|
|
# slash. Empty (the default) serves the app at the root exactly as before. A proxy that strips
|
|
# the prefix needs nothing here — the app derives the API address from its own URL.
|
|
ENV BASE_PATH=""
|
|
|
|
# Probe the port nginx was actually told to listen on (NGINX_PORT is configurable, so a
|
|
# hardcoded http://localhost/ breaks on any instance that changed it), and address it as
|
|
# 127.0.0.1: envsubst rewrites the conf after the image's IPv6 script, so nginx ends up
|
|
# listening on IPv4 only while "localhost" resolves to ::1 first.
|
|
HEALTHCHECK --interval=5m \
|
|
--timeout=5s \
|
|
--retries=3 \
|
|
CMD wget --spider -q "http://127.0.0.1:${NGINX_PORT}/" || exit 1
|
|
|