initial setup

This commit is contained in:
Jurgis Sakalauskas
2025-10-11 17:21:39 +03:00
commit ad2cf25bfd
37 changed files with 7084 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { apiFetch } from './http-client';
export type HealthResponse = {
status: string;
service: string;
};
export function getHealth() {
return apiFetch<HealthResponse>('/health');
}
+25
View File
@@ -0,0 +1,25 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? '/api';
type ApiFetchOptions = Omit<RequestInit, 'body'> & {
body?: Record<string, unknown>;
};
export async function apiFetch<TResponse>(path: string, options: ApiFetchOptions = {}): Promise<TResponse> {
const { body, headers, ...rest } = options;
const init: RequestInit = {
headers: {
'Content-Type': 'application/json',
...headers
},
body: body ? JSON.stringify(body) : undefined,
...rest
};
const response = await fetch(`${API_BASE_URL}${path}`, init);
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
return response.json() as Promise<TResponse>;
}