修复前端API配置,支持生产环境
This commit is contained in:
parent
072dacd3a7
commit
19ad7d6e00
@ -47,10 +47,10 @@ server {
|
|||||||
add_header X-Debug-Path $document_root$uri always;
|
add_header X-Debug-Path $document_root$uri always;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 后端API代理 - 使用正确的Docker网关地址
|
# 后端API代理 - 修复路径转发
|
||||||
location /api/ {
|
location /api/ {
|
||||||
# 使用Docker默认网桥的网关地址
|
# 使用Docker默认网桥的网关地址,并正确转发路径
|
||||||
proxy_pass http://172.17.0.1:8000/;
|
proxy_pass http://172.17.0.1:8000/api/;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@ -1,9 +1,19 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
// 根据环境设置API基础URL
|
||||||
|
const getBaseURL = () => {
|
||||||
|
// 如果是开发环境,使用localhost
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
return 'http://localhost:8000'
|
||||||
|
}
|
||||||
|
// 如果是生产环境,使用相对路径(会被nginx代理)
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: 'http://localhost:8000', // API的基础URL
|
baseURL: getBaseURL(), // API的基础URL
|
||||||
timeout: 15000 // 请求超时时间
|
timeout: 15000 // 请求超时时间
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user