add project
This commit is contained in:
28
apps/web/src/lib/api.ts
Normal file
28
apps/web/src/lib/api.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { webEnv } from './env';
|
||||
|
||||
const API_URL = webEnv.apiUrl;
|
||||
|
||||
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers as Record<string, string>),
|
||||
};
|
||||
|
||||
const res = await fetch(`${API_URL}${path}`, {
|
||||
...options,
|
||||
headers,
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.success) {
|
||||
throw new Error(data.error || 'Request failed');
|
||||
}
|
||||
|
||||
return data.data;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
getWallets: () => request<any>('/api/wallets'),
|
||||
};
|
||||
Reference in New Issue
Block a user