# Build stage
ARG REGISTRY_MIRROR=docker.1ms.run
FROM ${REGISTRY_MIRROR}/node:20-alpine AS builder

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
ARG VITE_API_BASE_URL=http://localhost:8100/api
ARG VITE_ENGINE_WS_URL=ws://localhost:8001/ws
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_ENGINE_WS_URL=$VITE_ENGINE_WS_URL
RUN npm run build

# Serve stage (no nginx – Node + serve on port 6000)
ARG REGISTRY_MIRROR=docker.1ms.run
FROM ${REGISTRY_MIRROR}/node:20-alpine

RUN npm install -g serve

WORKDIR /app
COPY --from=builder /app/dist ./dist

EXPOSE 6000

CMD ["serve", "-s", "dist", "-l", "6000"]
