diff --git a/.gitignore b/.gitignore index 478e099..3d669f4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,8 @@ target/ # 环境变量(含敏感信息,不提交) .env .env.local -.env.production +# .env.production 只含 API 地址,允许提交 +# .env.production # 保留开发环境配置(可按需注释掉) # .env.development diff --git a/reading-platform-frontend/.env.production b/reading-platform-frontend/.env.production new file mode 100644 index 0000000..909a1f3 --- /dev/null +++ b/reading-platform-frontend/.env.production @@ -0,0 +1,3 @@ +VITE_API_BASE_URL=http://8.148.151.56:3001/api/v1 +VITE_SERVER_BASE_URL=http://8.148.151.56:3001 +VITE_APP_TITLE=幼儿阅读教学服务平台 diff --git a/reading-platform-frontend/Dockerfile b/reading-platform-frontend/Dockerfile new file mode 100644 index 0000000..e37a65f --- /dev/null +++ b/reading-platform-frontend/Dockerfile @@ -0,0 +1,14 @@ +# 阶段一:编译 +FROM node:20-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install --registry=https://registry.npmmirror.com +COPY . . +RUN npx vite build + +# 阶段二:Nginx 服务 +FROM nginx:alpine +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/reading-platform-frontend/nginx.conf b/reading-platform-frontend/nginx.conf new file mode 100644 index 0000000..3dcafb8 --- /dev/null +++ b/reading-platform-frontend/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + # Vue Router history 模式支持 + location / { + try_files $uri $uri/ /index.html; + } + + # 反向代理后端 API + location /api/ { + proxy_pass http://backend:3001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + location /uploads/ { + proxy_pass http://backend:3001; + } +}