feat: add frontend app routing

This commit is contained in:
hailin
2026-06-30 18:47:35 +08:00
parent 333dc76f18
commit c80c286227
7 changed files with 77 additions and 5 deletions

17
frontend/src/lib/api.ts Normal file
View File

@@ -0,0 +1,17 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api'
export async function apiRequest<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE_URL}${path}`, {
headers: {
'content-type': 'application/json',
...init?.headers
},
...init
})
if (!response.ok) {
throw new Error(`API request failed: ${response.status}`)
}
return response.json() as Promise<T>
}