123
This commit is contained in:
42
frontend/src/api/client.js
Normal file
42
frontend/src/api/client.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:4000/api";
|
||||
|
||||
async function request(path, options = {}) {
|
||||
const response = await fetch(`${API_BASE_URL}${path}`, {
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(options.headers || {})
|
||||
},
|
||||
...options
|
||||
});
|
||||
|
||||
if (response.status === 204) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(payload.error || "Request failed");
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
me: () => request("/auth/me"),
|
||||
login: (body) => request("/auth/login", { method: "POST", body: JSON.stringify(body) }),
|
||||
logout: () => request("/auth/logout", { method: "POST" }),
|
||||
tables: () => request("/db/tables"),
|
||||
tableDetails: (tableName) => request(`/db/tables/${tableName}/details`),
|
||||
rows: (tableName, query = {}) => {
|
||||
const params = new URLSearchParams(query).toString();
|
||||
return request(`/db/tables/${tableName}/rows${params ? `?${params}` : ""}`);
|
||||
},
|
||||
executeSql: (sql) => request("/sql/execute", { method: "POST", body: JSON.stringify({ sql }) }),
|
||||
users: () => request("/admin/users"),
|
||||
roles: () => request("/admin/roles"),
|
||||
audit: (search = "") => request(`/admin/audit${search ? `?search=${encodeURIComponent(search)}` : ""}`),
|
||||
postgresLogs: (search = "") =>
|
||||
request(`/admin/postgres-logs${search ? `?search=${encodeURIComponent(search)}` : ""}`)
|
||||
};
|
||||
Reference in New Issue
Block a user