- 修复局域网访问
This commit is contained in:
+12
-6
@@ -1,9 +1,15 @@
|
|||||||
// API 基地址:Tauri 生产环境使用绝对路径,浏览器/开发环境使用相对路径
|
// API 基地址
|
||||||
// 判断依据:Tauri v2 在 Windows 上使用 https://tauri.localhost(protocol=https:),
|
// 同源请求(hostname=localhost/127.0.0.1):`''` 相对路径,开发模式或 macOS Tauri
|
||||||
// 在 macOS 上使用 tauri://localhost(protocol=tauri:),因此用 hostname 而非 protocol 判断
|
// Windows Tauri(hostname 含 "tauri"):后端在本机,固定 http://localhost:10801
|
||||||
const BASE = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
// 局域网访问(hostname 为 LAN IP):后端在同一台机器的 10801 端口
|
||||||
? '' // 同源请求(开发模式 localhost:1420 或浏览器)
|
const hostname = window.location.hostname;
|
||||||
: 'http://localhost:10801'; // Tauri 生产环境 (tauri://localhost / https://tauri.localhost)
|
const isLocal = hostname === 'localhost' || hostname === '127.0.0.1';
|
||||||
|
const isTauri = hostname.includes('tauri');
|
||||||
|
const BASE = isLocal
|
||||||
|
? ''
|
||||||
|
: isTauri
|
||||||
|
? 'http://localhost:10801'
|
||||||
|
: `http://${hostname}:10801`;
|
||||||
export const API_BASE = BASE;
|
export const API_BASE = BASE;
|
||||||
|
|
||||||
async function request(url, options = {}) {
|
async function request(url, options = {}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user