# Stage 1: Build
FROM node:20-alpine AS builder

WORKDIR /app

COPY package.json package-lock.json ./

# RUN npm config set registry https://mirror-npm.runflare.com
# RUN npm config set strict-ssl false

RUN npm config set registry https://registry.npmjs.org/ --global
RUN npm config set strict-ssl false

RUN npm ci

COPY . .

ARG VITE_API_BASE_URL
ARG VITE_USE_MOCKS=false

ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_USE_MOCKS=$VITE_USE_MOCKS

RUN npm run build

# Stage 2: Serve
FROM nginx:1.27-alpine

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

EXPOSE 80

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