# Base images pulled via the Docker Hub mirror (mirror.gcr.io) to avoid
# registry-1.docker.io timeouts. Revert to node:20-alpine / nginx:1.27-alpine
# if pulling direct from Docker Hub works in your environment.
# --- Build stage ---
FROM mirror.gcr.io/library/node:20-alpine AS build
WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm install

COPY . .

# API base URL is injected at build time (Vite inlines VITE_* vars).
# Defaults to same-origin /api, reverse-proxied to the backend by nginx.
ARG VITE_API_BASE_URL=/api
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build

# --- Serve stage ---
FROM mirror.gcr.io/library/nginx:1.27-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
