FROM node:22-slim AS builder

# Shown in the UI bundle manifest (plan step 8); the bundle's identity is its content hash
ARG APP_VERSION=0.0.0

WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm install --legacy-peer-deps

COPY . .
# Web build (served to browsers) + native UI bundle that phones download from
# this server: dist/downloads/waiter-bundle.json + waiter-bundle-<hash>.zip
RUN npm run build  && npx vite build --mode native  && APP_VERSION=$APP_VERSION node scripts/pack-bundle.mjs

FROM nginx:alpine

COPY --from=builder /app/dist /usr/share/nginx/html
RUN chmod -R 755 /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
