# 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 . .
# No VITE_API_URL build-arg needed: src/api/client.ts and src/api/fhirClient.ts
# use relative base URLs ("/api/v1", "/fhir") and rely on the nginx reverse proxy
# below to reach the api container at runtime — same origin in every environment.
RUN npm run build

FROM nginx:1.27-alpine AS runtime
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
