FROM node:20-alpine AS build

WORKDIR /app

COPY admin/package.json admin/package-lock.json ./
RUN npm ci

COPY admin/ .
RUN npm run build

# Production stage
FROM nginx:alpine

COPY --from=build /app/dist /usr/share/nginx/html

# SPA fallback
RUN echo 'server { \
  listen 5100; \
  root /usr/share/nginx/html; \
  index index.html; \
  location / { try_files $uri $uri/ /index.html; } \
  location /api/ { proxy_pass http://ccp-api:5000; } \
}' > /etc/nginx/conf.d/default.conf

EXPOSE 5100
