From ba737e18bd3b81c26f07e0a098756f821a8f3710 Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 13 May 2026 01:49:19 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8Dwin=E7=9A=84=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/api.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 = {}) {