FROM node:24
WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .

# next build writes the rewrite destinations from next.config.mjs into
# .next/routes-manifest.json, so "next start" cannot pick up a different
# API URL later. The value has to be known here, not just at runtime.
ARG API_INTERNAL_URL=http://localhost:3000
ENV API_INTERNAL_URL=$API_INTERNAL_URL

RUN npm run build:api && npm run build:web

RUN mkdir -p data && chmod +x scripts/docker-start.sh

EXPOSE 3001

CMD ["sh", "scripts/docker-start.sh"]
