# =============================================================
# freedom-web 前端镜像
# 构建阶段：node:16 构建 Vue 静态产物
# 运行阶段：nginx 托管静态文件 + 统一入口反代
#
# 注意：Vue 2.5 + vue-cli 3 为较老项目，固定使用 node:16 保证构建兼容
# =============================================================
FROM node:16-alpine AS builder
WORKDIR /build

# 复制依赖清单，利用 Docker 分层缓存（先安装依赖再复制源码）
COPY package.json .
RUN npm config set registry https://registry.npmmirror.com/ && \
    npm install --no-audit --no-fund || npm install --no-audit --no-fund --legacy-peer-deps

# 复制源码
COPY . .

# 构建生产产物（产物输出到 dist/）
RUN npm run build

# ---------- 运行阶段 ----------
FROM nginx:1.24-alpine
WORKDIR /usr/share/nginx/html

# 清理默认站点，复制构建产物
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /build/dist/ /usr/share/nginx/html/

# 统一入口 Nginx 配置（/api 反代到后端 + SPA 路由 + Excel 静态模板）
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 对外暴露端口
EXPOSE 80

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