# --- Etapa 1: build de la app React/Vite ---
FROM node:20-alpine AS build
WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

# VITE_API_URL debe pasarse como build-arg / env en el momento del build,
# ya que Vite la "quema" dentro del bundle estatico.
ARG VITE_API_URL
ENV VITE_API_URL=$VITE_API_URL

RUN npm run build

# --- Etapa 2: servir los archivos estaticos con nginx ---
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
