# Next.js standalone production Dockerfile
FROM node:18-alpine AS builder

WORKDIR /app

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

COPY . .

# Set API_BASE_URL at build time so Next.js inlines the correct value
# (Next.js replaces process.env.X at build time via DefinePlugin)
ARG API_BASE_URL=http://api-gateway:8000
ENV API_BASE_URL=${API_BASE_URL}

RUN npm run build

# ===== Production =====
FROM node:18-alpine

WORKDIR /app

ENV NODE_ENV=production

# Copy standalone server output (includes node_modules subset)
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public

EXPOSE 3000

CMD ["node", "server.js"]
