feat(frontend): add typed backend API client (openapi-fetch) with codegen script

This commit is contained in:
2026-07-06 01:52:25 +02:00
parent f58f6a0aa5
commit 93fe2fb942
6 changed files with 57 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
export type paths = Record<string, never>;
export type webhooks = Record<string, never>;
export type components = Record<string, never>;
export type operations = Record<string, never>;
+16
View File
@@ -0,0 +1,16 @@
import createClient from 'openapi-fetch';
import type { paths } from '$lib/api/schema';
import { apiConfig } from '$lib/server/config';
interface ApiClientOptions {
fetch: typeof fetch;
accessToken?: string;
}
export function createApiClient({ fetch, accessToken }: ApiClientOptions) {
return createClient<paths>({
baseUrl: apiConfig.baseUrl,
fetch,
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined
});
}
+6
View File
@@ -45,3 +45,9 @@ export const authConfig = {
return env.AUTH_ALLOW_INSECURE_HTTP === 'true';
}
};
export const apiConfig = {
get baseUrl() {
return (env.API_BASE_URL ?? '').replace(/\/+$/, '');
}
};