# Build a static SPA, then serve it with nginx. No Node at runtime.
FROM node:20-alpine AS build
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run gen || true
RUN npm run build

FROM nginx:1-alpine
COPY --from=build /app/dist /usr/share/nginx/html
# SPA fallback so client-side routing works under any path.
RUN printf 'server { listen 8080; root /usr/share/nginx/html; location / { try_files $uri /index.html; } location /api/ { proxy_pass http://backend.default.svc.cluster.local:50051/; } }\n' \
    > /etc/nginx/conf.d/default.conf
EXPOSE 8080
