From daa059e667c55146a5622dafcb816daffec19d90 Mon Sep 17 00:00:00 2001 From: ld3zian <42660576+ld3z@users.noreply.github.com> Date: Sun, 26 Jan 2025 12:09:10 -0700 Subject: [PATCH] fix search --- src/components/SlugInput.astro | 4 ++-- src/pages/api/comic/[slug].ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/pages/api/comic/[slug].ts diff --git a/src/components/SlugInput.astro b/src/components/SlugInput.astro index 860454c..f33b2b4 100644 --- a/src/components/SlugInput.astro +++ b/src/components/SlugInput.astro @@ -125,8 +125,8 @@ const languages = [ const promises = [...slugs].map(async (slug) => { try { - // Updated API endpoint to match ComicK's current structure - const response = await fetch(`https://api.comick.fun/comic/${encodeURIComponent(slug)}`); + // Use our API endpoint instead of direct ComicK API call + const response = await fetch(`/api/comic/${encodeURIComponent(slug)}`); if (!response.ok) throw new Error('Comic not found'); const data = await response.json(); diff --git a/src/pages/api/comic/[slug].ts b/src/pages/api/comic/[slug].ts new file mode 100644 index 0000000..3989c4a --- /dev/null +++ b/src/pages/api/comic/[slug].ts @@ -0,0 +1,31 @@ +import type { APIRoute } from "astro"; + +export const GET: APIRoute = async ({ params }) => { + const { slug } = params; + + try { + const response = await fetch( + `https://api.comick.fun/comic/${encodeURIComponent(slug!)}/` + ); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + return new Response(JSON.stringify(data), { + status: 200, + headers: { + 'Content-Type': 'application/json' + } + }); + } catch (error) { + console.error('Comic fetch error:', error); + return new Response(JSON.stringify({ error: 'Failed to fetch comic details' }), { + status: 500, + headers: { + 'Content-Type': 'application/json' + } + }); + } +}; \ No newline at end of file