mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56:37 +08:00
fix(frontend): keep browser API on same-origin rewrites in dev
Document that NEXT_PUBLIC_WAVELET_BACKEND_URL must stay unset for local next dev so axios hits /api/* and Next rewrites proxy to the backend.
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* API 配置
|
||||
*
|
||||
* 浏览器默认走同源相对路径(`/api/...`),由 `next.config` rewrites 反代到后端,
|
||||
* 避免 dev 下跨域。仅当设置了 `NEXT_PUBLIC_WAVELET_BACKEND_URL` 时浏览器才直连后端
|
||||
*(静态导出 embed / WebSocket 等场景)。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取 API 基础 URL
|
||||
* @returns API 基础 URL
|
||||
* @returns API 基础 URL;浏览器侧空字符串表示同源相对路径
|
||||
*/
|
||||
export function getApiBaseUrl(): string {
|
||||
if (typeof window === 'undefined') {
|
||||
@@ -14,6 +18,7 @@ export function getApiBaseUrl(): string {
|
||||
'http://localhost:8000'
|
||||
);
|
||||
}
|
||||
// 空字符串 → axios 请求 `/api/...`,经 Next rewrites 到后端,无 CORS 问题
|
||||
return process.env.NEXT_PUBLIC_WAVELET_BACKEND_URL || '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user