# ---- build stage ----
# ponytail: Bun replaces Node/yarn as the frontend build toolchain.
FROM oven/bun:1-alpine AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . ./
# When running behind nginx the SPA talks to the same origin via /api,
# so REACT_APP_BACKEND_URL can be left empty in Docker. Still allow override
# for the case where the user exposes the API directly.
ARG REACT_APP_BACKEND_URL=""
ENV REACT_APP_BACKEND_URL=$REACT_APP_BACKEND_URL
RUN bun run build

# ---- serve stage ----
FROM nginx:1.27-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
