# ===== Stage 1: Build the Angular app =====
FROM node:20-alpine AS builder

WORKDIR /app

# Copy package files for caching
COPY package*.json ./
RUN npm ci

# Copy source code
COPY . .

# Build for production
RUN npm run build -- --configuration production

# ===== Stage 2: Serve static files with Nginx (app service) =====
FROM nginx:alpine

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

# Copy built Angular app
COPY --from=builder /app/dist/niayesh-hospital /usr/share/nginx/html

# Copy app-specific Nginx config for SPA routing
COPY nginx_app.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

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