# Stage 1: Build React app
FROM node:20-alpine AS build

WORKDIR /app

# Copy root package.json and lockfile if any
COPY package.json package-lock.json* ./
COPY client-web/package.json ./client-web/

# Install dependencies specifically for client-web
RUN npm install

# Copy source code and shared resources
COPY client-web/ ./client-web/
COPY shared/ ./shared/

# Build web frontend
RUN cd client-web && npm run build

# Stage 2: Serve with Nginx
FROM nginx:alpine

# Copy built assets
COPY --from=build /app/client-web/dist /usr/share/nginx/html

# Custom Nginx config from docker/ folder
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

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