FROM node:20-alpine AS builder

WORKDIR /app

RUN npm config set registry https://package-mirror.liara.ir/repository/npm/ --global

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build 

FROM nginx:alpine

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

RUN cat <<'EOF' > /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;
    location /assets/ {
        try_files $uri =404;
        access_log off;
        expires 30d;
    }
    location / {
        try_files $uri $uri/ /index.html;
    }
}
EOF

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