first commit

This commit is contained in:
2026-05-09 00:38:56 +03:00
commit 51a44ef13d
156 changed files with 9832 additions and 0 deletions

27
src/shared/api/base.ts Normal file
View File

@@ -0,0 +1,27 @@
import { API_URL } from '@shared/config/env'
import { getCsrfToken } from './csrf'
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
const token = await getCsrfToken()
const res = await fetch(`${API_URL}${path}`, {
...options,
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': token,
...options.headers,
},
})
const data = await res.json()
if (!res.ok) throw data
return data as T
}
export const api = {
get: <T>(path: string) => request<T>(path),
post: <T>(path: string, body: unknown) =>
request<T>(path, { method: 'POST', body: JSON.stringify(body) }),
}