diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 134c747..f935dd2 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -3,7 +3,10 @@ import { useState, useEffect } from "react"; -const API_BASE = ""; // 使用相对路径,由 Next.js rewrite 代理到后端 +// 动态获取 API 地址:服务端使用 localhost,客户端使用当前域名 +const API_BASE = typeof window !== 'undefined' + ? `http://${window.location.hostname}:8006` + : 'http://localhost:8006'; // 类型定义 interface Material { diff --git a/frontend/src/app/publish/page.tsx b/frontend/src/app/publish/page.tsx index 62b2a51..b72eb7b 100644 --- a/frontend/src/app/publish/page.tsx +++ b/frontend/src/app/publish/page.tsx @@ -3,7 +3,10 @@ import { useState, useEffect } from "react"; import Link from "next/link"; -const API_BASE = ""; // 使用相对路径,由 Next.js rewrite 代理到后端 +// 动态获取 API 地址:服务端使用 localhost,客户端使用当前域名 +const API_BASE = typeof window !== 'undefined' + ? `http://${window.location.hostname}:8006` + : 'http://localhost:8006'; interface Account { platform: string;