# Stage 1: build the static bundle
FROM node:22-alpine AS builder

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

COPY . .

# SERVER_URL is baked into the bundle at build time (DefinePlugin), so it must be
# the address the user's browser can reach - not the compose-internal hostname.
ARG SERVER_URL=http://localhost:8000
ENV SERVER_URL=$SERVER_URL

# .env is excluded from the build context, so isDev in webpack.config.js has
# nothing to read - set NODE_ENV explicitly.
ENV NODE_ENV=production

RUN yarn build

# Stage 2: serve
FROM nginx:alpine

COPY --from=builder /app/dist /usr/share/nginx/html
COPY --from=builder /app/public /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
