diff --git a/src/utils/api.js b/src/utils/api.js index cc41be0..cb8368b 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,8 +1,9 @@ -// API 基地址:Tauri 生产环境使用绝对路径,浏览器环境使用相对路径 -// 导出供 SSE、媒体文件等非 fetch 场景使用 -const BASE = window.location.protocol === 'http:' || window.location.protocol === 'https:' - ? '' // 浏览器环境 — 同源请求 - : 'http://localhost:10801'; // Tauri 生产环境 (tauri://) +// API 基地址:Tauri 生产环境使用绝对路径,浏览器/开发环境使用相对路径 +// 判断依据:Tauri v2 在 Windows 上使用 https://tauri.localhost(protocol=https:), +// 在 macOS 上使用 tauri://localhost(protocol=tauri:),因此用 hostname 而非 protocol 判断 +const BASE = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' + ? '' // 同源请求(开发模式 localhost:1420 或浏览器) + : 'http://localhost:10801'; // Tauri 生产环境 (tauri://localhost / https://tauri.localhost) export const API_BASE = BASE; async function request(url, options = {}) {