# ---- Build stage ----
FROM node:20-alpine AS build
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .

# Which origin the built app calls comes from .env.production, committed next to
# this file, and Vite inlines it at build time.
#
# There is deliberately no ARG/ENV VITE_API_BASE_URL here. Vite gives a real
# environment variable precedence over its .env files, so declaring one with an
# empty default did not "leave it unset" - it actively set the value to an empty
# string and overrode .env.production. The build succeeded, the bundle shipped
# with no API base URL, and every request fell back to a relative /api/* that
# nginx forwards to a backend service this deployment does not have.
#
# To point a build somewhere else, edit .env.production, or add .env.local
# (ignored by git) - both are read by Vite and neither is silently empty.
RUN npm run build

# ---- Serve stage ----
FROM nginx:alpine
WORKDIR /usr/share/nginx/html

RUN rm -rf ./*
COPY --from=build /app/dist/ .
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80 3000
CMD ["nginx", "-g", "daemon off;"]
