feat(frontend): 添加 Docker 部署配置和生产环境变量
- Dockerfile:多阶段构建,node:20-alpine 编译 Vue3, nginx:alpine 提供静态资源服务,使用国内 npm 镜像加速 - nginx.conf:配置 Vue Router history 模式(try_files), /api/ 和 /uploads/ 反向代理到后端容器 - .env.production:生产环境 API 地址(8.148.151.56:3001) - .gitignore:放开 .env.production 提交权限(无敏感信息)
This commit is contained in:
parent
3a921250c3
commit
92071e5ba6
3
.gitignore
vendored
3
.gitignore
vendored
@ -19,7 +19,8 @@ target/
|
||||
# 环境变量(含敏感信息,不提交)
|
||||
.env
|
||||
.env.local
|
||||
.env.production
|
||||
# .env.production 只含 API 地址,允许提交
|
||||
# .env.production
|
||||
|
||||
# 保留开发环境配置(可按需注释掉)
|
||||
# .env.development
|
||||
|
||||
3
reading-platform-frontend/.env.production
Normal file
3
reading-platform-frontend/.env.production
Normal file
@ -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=幼儿阅读教学服务平台
|
||||
14
reading-platform-frontend/Dockerfile
Normal file
14
reading-platform-frontend/Dockerfile
Normal file
@ -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;"]
|
||||
21
reading-platform-frontend/nginx.conf
Normal file
21
reading-platform-frontend/nginx.conf
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user