feat: support cross-origin deployment with VITE_API_BASE_URL
- Set VITE_API_BASE_URL=https://opinion-api.moreminimore.com for frontend-backend split deployment - Vite proxy also uses API_BACKEND_URL env var as target - Falls back to same-origin proxy for local dev
This commit is contained in:
10
.env.example
10
.env.example
@@ -69,6 +69,16 @@ LLM_MODEL_NAME=qwen-plus
|
||||
ZEP_API_KEY=your_zep_api_key_here
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Frontend URL 配置
|
||||
# ================================================================
|
||||
# 前后端分离部署时(如 opinion.moreminimore.com + opinion-api.moreminimore.com),
|
||||
# 设置此变量让前端直接请求后端 API 地址。
|
||||
# 同源部署或本地开发时无需设置。
|
||||
|
||||
VITE_API_BASE_URL=https://opinion-api.moreminimore.com
|
||||
|
||||
|
||||
# ================================================================
|
||||
# 加速 LLM 配置(可选)
|
||||
# ================================================================
|
||||
|
||||
@@ -2,6 +2,9 @@ import axios from 'axios'
|
||||
import i18n from '../i18n'
|
||||
|
||||
// 创建axios实例
|
||||
// VITE_API_BASE_URL: set to backend URL for cross-origin deployments
|
||||
// e.g. https://opinion-api.moreminimore.com
|
||||
// Falls back to '' (empty) when using vite proxy (same-origin / local dev)
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || '',
|
||||
timeout: 300000, // 5分钟超时(本体生成可能需要较长时间)
|
||||
|
||||
@@ -18,9 +18,9 @@ export default defineConfig({
|
||||
allowedHosts: true,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:5001',
|
||||
target: process.env.API_BACKEND_URL || 'http://localhost:5001',
|
||||
changeOrigin: true,
|
||||
secure: false
|
||||
secure: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user