add frontend

This commit is contained in:
voltsrage
2026-06-19 17:42:09 +08:00
parent 49973271e5
commit 5f69ce1a95
53 changed files with 6591 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
const BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5270'
async function request(path, options = {}) {
const res = await fetch(`${BASE_URL}${path}`, {
headers: { 'Content-Type': 'application/json', ...options.headers },
...options,
})
const envelope = await res.json()
if (!res.ok || !envelope.success) {
const msg = envelope.error?.message ?? `API ${res.status}: ${path}`
throw new Error(msg)
}
return envelope.data
}
export const api = {
get: (path) => request(path),
post: (path, body) => request(path, {
method: 'POST',
body: body !== undefined ? JSON.stringify(body) : undefined,
}),
}