18 lines
472 B
TypeScript
18 lines
472 B
TypeScript
export const baseUrl = import.meta.env.VITE_BASE_URL as string;
|
|
export default async function api(path: string, data: any): Promise<any> {
|
|
const request = new Request(`${baseUrl}${path}/`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(data),
|
|
});
|
|
let response: Response;
|
|
try {
|
|
response = await fetch(request);
|
|
} catch (e) {
|
|
throw new Error(`request failed: ${e}`);
|
|
}
|
|
return response;
|
|
}
|