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:
@@ -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