Files
aiartstudio/server/utils/fetch.ts
T
2026-04-24 15:36:44 +08:00

26 lines
708 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 上游 NewAPI 服务的根地址 */
const BASE_URL = "https://api.qflink.xyz";
/**
* 向上游 NewAPI 发起请求
*
* @param path 相对路径,如 "/api/user/register",会自动拼接到 BASE_URL 后面
* @param options 透传给 $fetch 的所有选项(method、body、headers 等)
* @returns Promise<T>T 是上游返回的数据类型
*
* @example
* const result = await newApiFetch<string>("/api/user/register", {
* method: "POST",
* body: { username: "xxx" }
* })
*/
export const newApiFetch = <T>(
path: string,
options?: Parameters<typeof $fetch>[1]
): Promise<T> => {
return $fetch<T>(path, {
baseURL: BASE_URL,
...options
}) as Promise<T>;
};