I have a +layout.server.ts
in my SvelteKit application which should load some data from an api endpoint. It looks similar to this:
import { env } from '$env/dynamic/public';export const load: LayoutServerLoad = async ({ fetch }) => { const apiUrl = `${env.PUBLIC_API_URI}/some/subpath`; console.log('Fetching data', { apiUrl }); const res = await fetch(apiUrl); Log.debug('Fetched flow', { apiUrl, status: res.status }); if (!res.ok) { error(500, 'failed to fetch data'); } // Some more logic and a return};
In my local dev environment everything works fine. Things get wired if I deploy this application to my Kubernetes Cluster.
In my deployment the PUBLIC_API_URI
is set to something like https://example.com/api
. I also have an Ingress configured which routes the traffic to different services.
https://example.com/**/* --> goes to the svelte applicationhttps://example.com/api/**/* --> goes to my api service
The fetch request inside the LayoutServerLoad
gets routed to my svelte application. I expect that the fetch request is handled by the api service.
The wired thing is that when I open the url which gets logged by the line console.log('Fetching data', { apiUrl });
in my browser the request is handled by the api service as expected. So I guess my ingress configuration is not the problem.
Has anyone an idea why the fetch call is not handled by the api service?