重构后端成功

This commit is contained in:
2026-04-28 00:45:18 +08:00
parent dd17206e1f
commit 8b10ef5828
75 changed files with 244 additions and 16685 deletions

View File

@@ -1,5 +1,5 @@
# 使用 Node.js 18 Alpine 镜像作为基础
FROM node:18-alpine
# 多阶段构建 - 开发环境
FROM node:20-alpine AS development
# 设置工作目录
WORKDIR /app
@@ -8,15 +8,55 @@ WORKDIR /app
RUN npm config set registry https://registry.npmmirror.com/
# 复制 package.json 和 package-lock.json
# 利用 Docker 缓存层,只有依赖变更时才重新安装
COPY package.json package-lock.json* ./
# 安装依赖
RUN npm install
# 复制源代码到容器
COPY . .
# 暴露 Vite 默认端口 5173
EXPOSE 5173
# 启动命令由 docker-compose.yml 中的 command 覆盖,
# 这里保留默认的 dev 命令作为 fallback
# 设置环境变量
ENV NODE_ENV=development
ENV VITE_API_URL=http://backend:8000/api
# 启动 Vite 开发服务器
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
# 多阶段构建 - 生产环境
FROM node:20-alpine AS build
WORKDIR /app
# 设置 npm 镜像源
RUN npm config set registry https://registry.npmmirror.com/
# 复制依赖文件
COPY package.json package-lock.json* ./
# 安装依赖
RUN npm install
# 复制源代码
COPY . .
# 构建生产版本
RUN npm run build
# 生产环境镜像
FROM nginx:alpine AS production
# 复制构建产物到 Nginx
COPY --from=build /app/dist /usr/share/nginx/html
# 复制 Nginx 配置文件
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]