config.ts 761 B

12345678910111213141516171819
  1. // 统一的 API 配置
  2. // 推荐生产形态(形态2):同域反向代理,把后端挂到 /api 下。
  3. // 这样无需在前端产物里写死域名/端口(避免 Docker 镜像里固化 localhost)。
  4. export const API_BASE_URL = "";
  5. export const API_PREFIX = "/api";
  6. export function apiUrl(path: string): string {
  7. const p = path.startsWith("/") ? path : `/${path}`;
  8. return `${API_BASE_URL}${API_PREFIX}${p}`;
  9. }
  10. /** 知识库/文档/导入等接口需带当前用户 ID,供后端校验「是否开放知识库」开关 */
  11. export function getAgentHeaders(): Record<string, string> {
  12. if (typeof window === "undefined") return {};
  13. const id = window.localStorage.getItem("agent_user_id");
  14. if (!id) return {};
  15. return { "X-User-Id": id };
  16. }