# --- etap 1: build ---
FROM node:22-alpine AS build
WORKDIR /build

# najpierw manifesty, zeby warstwa z node_modules byla cache'owana
COPY package.json package-lock.json ./
RUN npm ci

COPY . .

# frontend odpytuje backend przez wzgledny /api, ktory nginx proxuje dalej
ARG VITE_API_URL=/api
ENV VITE_API_URL=$VITE_API_URL
RUN npm run build

# --- etap 2: runtime ---
FROM nginx:1.27-alpine

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

EXPOSE 80

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