# Stage 1: Build
FROM node:18 AS builder

WORKDIR /app

COPY . .

# Install dependencies with legacy peer deps to avoid version conflicts
RUN npm install --legacy-peer-deps && npm run build

# Stage 2: Serve with Nginx
FROM nginx:alpine

# Remove default nginx static files
RUN rm -rf /usr/share/nginx/html/*

# Copy built files from builder
COPY --from=builder /app/dist /usr/share/nginx/html

# Copy custom Nginx config if needed
# COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

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