# Build context is vigilcare-records-web/ (package.json, nginx.conf live here):
#   docker build -f vigilcare-records-web/Dockerfile -t vigilcare-records-dashboard vigilcare-records-web

FROM node:22-alpine AS build
WORKDIR /app

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

COPY . .
# Typecheck runs in CI (npm run typecheck). Image build is vite only.
# No VITE_API_URL build-arg: src/api/client.ts and src/api/fhirClient.ts use
# relative base URLs ("/api/v1", "/fhir"); nginx reverse-proxies to the api
# container — same origin in every environment.
RUN npx vite build

FROM nginx:1.27-alpine AS final
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD wget -qO- http://localhost:80/ >/dev/null || exit 1

EXPOSE 80
