# syntax=docker/dockerfile:1

FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

FROM node:20-alpine AS builder
WORKDIR /app
# The /plans/[code] route uses generateStaticParams + dynamicParams = false,
# so PLANS_PAGES must be known at build time — codes not baked in here will
# 404 at runtime no matter what PLANS_PAGES is set to when the container runs.
ARG PLANS_PAGES
ENV PLANS_PAGES=$PLANS_PAGES
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0

COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

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