FROM docker.io/library/node:latest as builder

WORKDIR /app

COPY frontend/package.json .

RUN npm install

COPY frontend/ .

RUN npm run build

FROM eci-nydus-registry.cn-hangzhou.cr.aliyuncs.com/docker/nginx:latest

COPY --from=builder /app/dist /usr/share/nginx/html

RUN echo 'server { \
    listen       8082; \
    server_name  localhost; \
    root   /usr/share/nginx/html; \
    index  index.html; \
    location / { \
        try_files $uri $uri/ /index.html; \
    } \
    location /api { \
        proxy_pass http://gateway:8081; \
        proxy_set_header Host $host; \
        proxy_set_header X-Real-IP $remote_addr; \
    } \
}' > /etc/nginx/conf.d/default.conf

EXPOSE 8082

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