FROM node:20-alpine

WORKDIR /app

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

# App source.
COPY server.js ./
COPY public ./public

ENV PORT=3000
EXPOSE 3000

# Lightweight container healthcheck against the API.
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
  CMD wget -qO- http://localhost:3000/api/config > /dev/null || exit 1

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