| 1234567891011121314151617181920 |
- import { apiHost, isServer } from "../../libs/config";
- import type { ResData } from "../../types/http";
- export function http<T = any>(uri: string, config?: RequestInit) {
- return fetch(isServer ? `${apiHost}${uri}` : uri, config).then((res) =>
- res.json()
- ) as Promise<ResData<T>>;
- }
- export function get<T = any>(uri: string) {
- return http<T>(uri);
- }
- export function post<T = any>(uri: string, body?: unknown) {
- return http<T>(uri, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(body),
- });
- }
|