cutt/src/api.ts

18 lines
472 B
TypeScript
Raw Normal View History

2025-01-26 16:20:27 +01:00
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;
}