Cong123779's picture
feat: add favicon, OG image, dual DB adapter (Supabase+SQLite), api utility
7c46a3a verified
Raw
History Blame Contribute Delete
1.13 kB
// Tự động chọn base URL:
// - Production (Vercel): dùng VITE_API_URL trỏ về HF Space
// - Development (local): dùng '' để Vite proxy forward về localhost:5000
const BASE_URL = import.meta.env.VITE_API_URL || '';
export const api = {
get: (path, token = null) =>
fetch(`${BASE_URL}${path}`, {
headers: token ? { Authorization: `Bearer ${token}` } : {}
}).then(r => r.json()),
post: (path, body, token = null) =>
fetch(`${BASE_URL}${path}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {})
},
body: JSON.stringify(body)
}).then(r => r.json()),
put: (path, body, token) =>
fetch(`${BASE_URL}${path}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify(body)
}).then(r => r.json()),
delete: (path, token) =>
fetch(`${BASE_URL}${path}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` }
}).then(r => r.json()),
};