diff --git a/packages/frontend/src/lib/services.ts b/packages/frontend/src/lib/services.ts index 376ead9..8eb736f 100644 --- a/packages/frontend/src/lib/services.ts +++ b/packages/frontend/src/lib/services.ts @@ -220,18 +220,17 @@ export async function getVideosForModel(id, fetch?: typeof globalThis.fetch) { export async function getFeaturedVideos( limit: number, - fetch?: typeof globalThis.fetch, + fetchFn: typeof globalThis.fetch = globalThis.fetch, ) { return loggedApiCall( "getFeaturedVideos", async () => { - const directus = getDirectusInstance(fetch); - return directus.request( - customEndpoint({ - method: "GET", - path: `/sexy/videos?featured=true&limit=${limit}`, - }), - ); + const url = `${PUBLIC_URL}/api/sexy/videos?featured=true&limit=${limit}`; + const response = await fetchFn(url); + if (!response.ok) { + throw new Error(`Failed to fetch featured videos: ${response.statusText}`); + } + return (await response.json()) as Video[]; }, { limit }, ); @@ -290,18 +289,17 @@ export async function getModels(fetch?: typeof globalThis.fetch) { export async function getFeaturedModels( limit = 3, - fetch?: typeof globalThis.fetch, + fetchFn: typeof globalThis.fetch = globalThis.fetch, ) { return loggedApiCall( "getFeaturedModels", async () => { - const directus = getDirectusInstance(fetch); - return directus.request( - customEndpoint({ - method: "GET", - path: `/sexy/models?featured=true&limit=${limit}`, - }), - ); + const url = `${PUBLIC_URL}/api/sexy/models?featured=true&limit=${limit}`; + const response = await fetchFn(url); + if (!response.ok) { + throw new Error(`Failed to fetch featured models: ${response.statusText}`); + } + return (await response.json()) as Model[]; }, { limit }, ); diff --git a/packages/frontend/src/routes/+page.server.ts b/packages/frontend/src/routes/+page.server.ts index 5b1e9e4..6c5a1f3 100644 --- a/packages/frontend/src/routes/+page.server.ts +++ b/packages/frontend/src/routes/+page.server.ts @@ -1,13 +1,7 @@ import { getFeaturedModels, getFeaturedVideos } from "$lib/services"; export async function load({ fetch }) { - const [models, videos] = await Promise.all([ - getFeaturedModels(3, fetch), - getFeaturedVideos(3, fetch), - ]); - - // Ensure data is serializable by converting to plain JSON return { - models: JSON.parse(JSON.stringify(models)), - videos: JSON.parse(JSON.stringify(videos)), + models: await getFeaturedModels(3, fetch), + videos: await getFeaturedVideos(3, fetch), }; }