# Multi-stage build for the CRDC Arrests API Demo app.
# Stage 1: Build static files with Vite + React
FROM node:22-alpine AS builder

WORKDIR /app
COPY package*.json ./
RUN npm ci --prefer-offline

COPY . .
# The VITE_API_BASE env var can be set at build time to point to a different API endpoint.
ARG VITE_API_BASE=https://crdc-api.civilytics.org/api/v1
ENV VITE_API_BASE=${VITE_API_BASE}
RUN npm run build

# Stage 2: Serve with nginx (tiny image, ~5MB)
FROM nginx:alpine AS runtime
COPY --from=builder /app/dist/ /usr/share/nginx/html/
# Custom nginx config for SPA routing + caching headers
COPY nginx.conf /etc/nginx/conf.d/default.conf

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