# Build the React app, then run it from the API process (one container, one port).
FROM node:22-slim AS web
WORKDIR /app/client
COPY client/package*.json ./
RUN npm ci
COPY client/ ./
RUN npm run build

FROM node:22-slim AS api
ENV NODE_ENV=production
WORKDIR /app/server
RUN apt-get update && apt-get install -y --no-install-recommends python3 build-essential \
  && rm -rf /var/lib/apt/lists/*
COPY server/package*.json ./
RUN npm ci --omit=dev
COPY server/ ./
COPY --from=web /app/client/dist /app/client/dist
ENV PORT=4000 DATA_DIR=/data UPLOAD_DIR=/data/uploads
VOLUME ["/data"]
EXPOSE 4000
CMD ["node", "src/index.js"]
