# Use Node.js as the base image
FROM node:22.17.1-bookworm-slim

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json
COPY front/package*.json ./

# Instalar exactamente lo del lock: npm install reescribiría el lock si no cuadra
# con package.json, y la imagen dejaría de ser reproducible
RUN npm ci

# Copy the rest of the application
COPY front/ .

# La URL de la API no se hornea: la lee el proxy /api al arrancar (API_URL)
ARG VITE_ALLOWED_HOSTS
ENV VITE_ALLOWED_HOSTS=${VITE_ALLOWED_HOSTS}

# Build the React application
RUN npm run build

# Expose the port the app runs on
EXPOSE 80 5173

# Copiar y usar el entrypoint, que sirve el build con `npm run preview`
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]
