增加不同环境的配置
This commit is contained in:
parent
1fa9a3acc7
commit
877d7c035b
32
Dockerfile
32
Dockerfile
@ -1,7 +1,14 @@
|
||||
# 构建阶段
|
||||
FROM node:16-alpine as builder
|
||||
FROM node:16 as builder
|
||||
|
||||
# 设置构建参数
|
||||
ARG BUILD_ENV=testing
|
||||
ARG API_URL
|
||||
|
||||
# 设置环境变量
|
||||
ENV NODE_ENV=${BUILD_ENV}
|
||||
ENV VUE_APP_API_URL=${API_URL}
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 package.json 和 package-lock.json
|
||||
@ -13,23 +20,18 @@ RUN npm install
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建项目
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 生产阶段
|
||||
FROM node:16-alpine
|
||||
FROM nginx:alpine
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
# 复制 nginx 配置
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 安装 serve 包来提供静态文件服务
|
||||
RUN npm install -g serve
|
||||
# 从构建阶段复制构建结果
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# 从构建阶段复制构建产物
|
||||
COPY --from=builder /app/dist ./dist
|
||||
EXPOSE 80
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 3000
|
||||
|
||||
# 启动服务
|
||||
CMD ["serve", "-s", "dist", "-l", "3000"]
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
18
nginx.conf
18
nginx.conf
@ -3,21 +3,21 @@ server {
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
index index.html;
|
||||
|
||||
# 支持 history 路由模式
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 配置 API 代理(根据实际需求修改)
|
||||
location /api {
|
||||
proxy_pass http://backend-service; # 替换为实际的后端服务地址
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
# 缓存静态资源
|
||||
location /assets {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
# 禁止访问 . 文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
13
src/config/env.js
Normal file
13
src/config/env.js
Normal file
@ -0,0 +1,13 @@
|
||||
const env = {
|
||||
development: {
|
||||
API_URL: 'http://localhost:8080'
|
||||
},
|
||||
testing: {
|
||||
API_URL: process.env.VUE_APP_API_URL || 'https://api-dev.ibtc.work'
|
||||
},
|
||||
production: {
|
||||
API_URL: process.env.VUE_APP_API_URL || 'http://api.example.com'
|
||||
}
|
||||
}
|
||||
|
||||
export default env[process.env.NODE_ENV || 'development']
|
||||
@ -1,9 +1,10 @@
|
||||
import axios from 'axios'
|
||||
import { message } from 'ant-design-vue'
|
||||
import config from '@/config/env'
|
||||
|
||||
const request = axios.create({
|
||||
baseURL: 'http://127.0.0.1:8000',
|
||||
timeout: 5000,
|
||||
baseURL: config.API_URL,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user