18 lines
465 B
TypeScript
18 lines
465 B
TypeScript
|
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;
|
||
|
}
|