25 lines
606 B
TypeScript
25 lines
606 B
TypeScript
const API_URL = "http://localhost:9000";
|
|
|
|
const ACCESS_TOKEN =
|
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3Mzg0MjY1MDMsInVzZXJfaWQiOiI1a3hERGNvSFpTQkM3dUVZc20zRnZrdEsifQ.Z3xceSQKjDg5nHQel3jGlUDjWiCjDUmhFgJtrirxyew";
|
|
|
|
export async function fetchAPI<Body>(
|
|
url: string,
|
|
options?: RequestInit,
|
|
): Promise<Body> {
|
|
const response = await fetch(`${API_URL}${url}`, {
|
|
...options,
|
|
headers: {
|
|
authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
...options?.headers,
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Network response was not ok");
|
|
}
|
|
|
|
const body = await response.json();
|
|
|
|
return body;
|
|
}
|