Wire frontend into Docker Compose with type-safe API client

- Add frontend service to docker-compose.yml (port 3000, BACKEND_URL env var)
- Add frontend/Dockerfile using adapter-node for plain Node/Docker runtime
- Switch svelte.config.js from adapter-auto to adapter-node
- Generate OpenAPI types from backend spec (openapi-typescript + openapi-fetch)
- Add src/lib/server/api.ts as server-only typed API client factory
- Add generate:api script to regenerate types when backend spec changes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 12:36:09 +02:00
parent b36d4c731d
commit 82815205d0
8 changed files with 6135 additions and 0 deletions

File diff suppressed because one or more lines are too long

1992
frontend/src/lib/api/schema.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
import createClient from 'openapi-fetch';
import type { paths } from '$lib/api/schema.d.ts';
import { env } from '$env/dynamic/private';
// Usage in +page.server.ts load functions and form actions:
//
// export const load = async ({ fetch }) => {
// const api = apiClient(fetch);
// const { data, error } = await api.GET('/v1/recipes', { ... });
// };
//
// Always pass SvelteKit's `fetch` so session cookies are forwarded correctly.
export function apiClient(fetch?: typeof globalThis.fetch) {
return createClient<paths>({
baseUrl: env.BACKEND_URL ?? 'http://localhost:8080',
fetch: fetch ?? globalThis.fetch
});
}