FROM node:20-alpine AS build

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .

# Build args for API URL
ARG PUBLIC_API_URL=https://api.sumbatengahkab.go.id/api
ENV PUBLIC_API_URL=$PUBLIC_API_URL

RUN npm run build

# Production — serve static files with lightweight server
FROM nginx:alpine AS production

COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
  CMD wget -qO- http://localhost:80/ || exit 1
