FROM node:22-bookworm-slim

WORKDIR /app

# registry.npmjs.org resolves to Cloudflare's IPv6-only records here, and
# Docker's default bridge network has flaky IPv6 egress — Node's Happy
# Eyeballs then hangs on IPv6 before timing out instead of falling back to
# IPv4 quickly, causing intermittent ETIMEDOUT mid-install.
ENV NODE_OPTIONS=--dns-result-order=ipv4first

COPY package.json package-lock.json* ./
# registry.npmjs.org itself is unreliable from this host (mid-download
# stalls even with aggressive npm retries) — route through npmmirror.com
# instead, which is consistently reachable from this network.
RUN npm config set registry https://registry.npmmirror.com && \
    npm config set fetch-retries 8 && \
    npm config set fetch-retry-mintimeout 20000 && \
    npm config set fetch-retry-maxtimeout 120000 && \
    npm install

COPY . .
RUN npm run build

CMD ["npm", "start", "--", "--hostname", "0.0.0.0"]

