fix: add frontend/src/lib/ to git (was ignored by /lib/ pattern)
Some checks failed
Deploy to Homelab / Deploy Wordly to 192.168.1.151 (push) Has been cancelled
Deploy to Homelab / Deploy Monitoring (if configured) (push) Has been cancelled

The root .gitignore had `lib/` which matched frontend/src/lib/,
causing Docker build to fail with "Module not found: Can't resolve
'@/lib/utils'" and '@/lib/i18n'.

Changed to `/lib/` so it only ignores the Python lib at repo root.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 15:17:22 +02:00
parent 98d82414bb
commit 05c5dfcbbb
10 changed files with 9115 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
import { API_BASE } from "./config";
export class ApiClientError extends Error {
status: number;
code?: string;
constructor(status: number, message: string, code?: string) {
super(message);
this.name = "ApiClientError";
this.status = status;
this.code = code;
}
}
async function request<T>(
method: string,
url: string,
body?: unknown,
): Promise<T> {
const headers: Record<string, string> = {};
const token =
typeof window !== "undefined" ? localStorage.getItem("token") : null;
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}
if (body !== undefined) {
headers["Content-Type"] = "application/json";
}
const res = await fetch(`${API_BASE}${url}`, {
method,
headers,
body: body !== undefined ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
let message = `HTTP ${res.status}`;
let code: string | undefined;
try {
const json = await res.json();
message = json.message || json.error || json.detail || message;
code = json.code;
} catch {}
throw new ApiClientError(res.status, message, code);
}
if (res.status === 204) return undefined as T;
const json = await res.json();
return json as T;
}
export const apiClient = {
get: <T>(url: string) => request<T>("GET", url),
post: <T>(url: string, body?: unknown) => request<T>("POST", url, body),
patch: <T>(url: string, body?: unknown) => request<T>("PATCH", url, body),
put: <T>(url: string, body?: unknown) => request<T>("PUT", url, body),
delete: <T>(url: string) => request<T>("DELETE", url),
};
export const API_BASE_URL = API_BASE;