Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Has been cancelled
CI / Backend Unit Tests (pull_request) Has been cancelled
CI / E2E Tests (pull_request) Has been cancelled
Both SvelteKit API proxy routes were hardcoding http://localhost:8080, breaking typeahead search in Docker environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { env } from 'process';
|
|
|
|
export const GET: RequestHandler = async ({ url, fetch }) => {
|
|
// 1. Suchparameter aus der URL des Browsers holen
|
|
const q = url.searchParams.get('q') || '';
|
|
|
|
try {
|
|
// 3. Anfrage an das Java-Backend weiterleiten (Server-to-Server)
|
|
// Wir nutzen hier den internen Docker-Hostnamen oder localhost, je nach Netzwerk
|
|
const backendUrl = `${env.API_INTERNAL_URL || 'http://localhost:8080'}/api/persons?q=${encodeURIComponent(q)}`;
|
|
|
|
const response = await fetch(backendUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error(`Backend Error: ${response.status}`);
|
|
return json([], { status: response.status });
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
// 4. Daten zurück an den Browser schicken
|
|
return json(data);
|
|
|
|
} catch (error) {
|
|
console.error("Proxy Error:", error);
|
|
return json([], { status: 500 });
|
|
}
|
|
};
|