# FunZone Accounting Frontend Dockerfile
FROM node:18-alpine AS build

WORKDIR /app

ARG VITE_API_BASE_URL=http://localhost:8001/api
ARG VITE_ACCOUNTING_BASE_URL=http://localhost:8010/api
ARG VITE_BASE_PATH=/
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_ACCOUNTING_BASE_URL=$VITE_ACCOUNTING_BASE_URL
ENV VITE_BASE_PATH=$VITE_BASE_PATH

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

FROM nginx:alpine

RUN apk add --no-cache curl

COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD curl -f http://localhost/health || exit 1

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