FROM node:20-alpine

WORKDIR /build

# Copy both cf-webapp and common
COPY cf-webapp ./cf-webapp
COPY common ./common

# Install ALL dependencies for build
WORKDIR /build/cf-webapp
RUN npm ci

# Build Next.js
RUN npm run build

# Production stage
FROM node:20-alpine

WORKDIR /app

# Copy entire built application (simpler approach)
COPY --from=0 /build/cf-webapp ./
COPY --from=0 /build/common ../common

EXPOSE 3000

CMD ["npm", "start"]