fix: use hostname:8000 as API fallback for remote deployments

Replace hardcoded localhost:8000 with window.location.hostname:8000 so the
frontend auto-detects the correct backend address when deployed on a remote
server instead of always pointing to localhost.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 22:22:46 +08:00
parent b8561e04c6
commit 3f12e96ea0
4 changed files with 12 additions and 31 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ import type {
} from "@/types";
// API基础配置
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}/api` : "http://127.0.0.1:8000");
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.hostname}:8000` : "http://127.0.0.1:8000");
// 请求拦截器
async function apiRequest<T>(