@@ -0,0 +1,25 @@
|
||||
/** 上游 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>;
|
||||
};
|
||||
Reference in New Issue
Block a user