This commit is contained in:
Sakurasan
2026-07-06 02:30:38 +08:00
parent 9682c91224
commit cffdea5407
2 changed files with 13 additions and 7 deletions
+10 -3
View File
@@ -1,6 +1,13 @@
// Python 后端 API 客户端 — 自动适配局域网 IP
// 前端 JS 在浏览器中运行时,API 用当前页面的 hostname(端口 8000
const API_BASE = `http://${window.location.hostname}:8000`;
// Python 后端 API 客户端
// 生产环境:同源反代,用相对路径
// 开发环境:Vite 3015 → 后端 8000,显式跨域
const API_BASE = (() => {
const { hostname, port } = window.location;
if (port === '3015') {
return `http://${hostname}:8000`;
}
return '';
})();
export function getApiBaseUrl(): string {
return API_BASE;