ChatGPT-Next-Web/app/utils/cors.ts

20 lines
425 B
TypeScript
Raw Normal View History

2023-09-12 18:51:02 +00:00
import { getClientConfig } from "../config/client";
import { ApiPath, DEFAULT_API_HOST } from "../constant";
2023-09-12 18:51:02 +00:00
export function corsPath(path: string) {
const baseUrl = getClientConfig()?.isApp ? `${DEFAULT_API_HOST}` : "";
2023-09-12 18:51:02 +00:00
2024-03-13 19:03:46 +00:00
if (baseUrl === "" && path === "") {
return "";
}
2023-09-12 18:51:02 +00:00
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.endsWith("/")) {
path += "/";
}
return `${baseUrl}${path}`;
}