FROM node:20-alpine
WORKDIR /app

# Install production deps first for layer caching.
COPY package.json ./
RUN npm install --omit=dev

COPY . .

ENV NODE_ENV=production
EXPOSE 4000

HEALTHCHECK --interval=30s --timeout=4s --start-period=8s --retries=3 \
  CMD wget -qO- http://localhost:4000/api/health >/dev/null 2>&1 || exit 1

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