# frontend/Dockerfile
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./

ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm ci --silent --legacy-peer-deps

COPY . .
ARG REACT_APP_API_URL=""
ARG PUBLIC_URL=/
ENV REACT_APP_API_URL=${REACT_APP_API_URL}
ENV PUBLIC_URL=${PUBLIC_URL}

RUN npm run build

# nginx pour servir les fichiers statiques
FROM nginx:stable-alpine AS runner

# Copy build output
COPY --from=builder /app/build /usr/share/nginx/html

COPY nginx-spa.conf /etc/nginx/conf.d/default.conf

# Expose port 80 (Caddy fera reverse proxy)
EXPOSE 80

# Utilisateur par défaut (nginx image gère user)
CMD ["nginx", "-g", "daemon off;"]