diff --git a/src/components/SlugInput.astro b/src/components/SlugInput.astro
index 94db311..c295713 100644
--- a/src/components/SlugInput.astro
+++ b/src/components/SlugInput.astro
@@ -145,11 +145,37 @@ const languages = [
}
try {
- const response = await fetch(`https://api.comick.io/v1.0/search/?page=1&limit=5&q=${encodeURIComponent(query)}`);
+ searchResults!.innerHTML = `
+
+ Searching...
+
+ `;
+ searchResults!.classList.remove('hidden');
+
+ const response = await fetch('/api/search', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ query })
+ });
+
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
const data = await response.json();
+ if (!data || !Array.isArray(data) || data.length === 0) {
+ searchResults!.innerHTML = `
+
+ No comics found
+
+ `;
+ return;
+ }
+
searchResults!.innerHTML = '';
- searchResults!.classList.remove('hidden');
data.forEach((comic: any) => {
const div = document.createElement('div');
diff --git a/src/pages/api/search.ts b/src/pages/api/search.ts
new file mode 100644
index 0000000..bccfc41
--- /dev/null
+++ b/src/pages/api/search.ts
@@ -0,0 +1,31 @@
+import type { APIRoute } from "astro";
+
+export const POST: APIRoute = async ({ request }) => {
+ const { query } = await request.json();
+
+ try {
+ const response = await fetch(
+ `https://api.comick.io/v1.0/search/?page=1&limit=5&q=${encodeURIComponent(query)}`
+ );
+
+ 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('Search error:', error);
+ return new Response(JSON.stringify({ error: 'Failed to search comics' }), {
+ status: 500,
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ });
+ }
+};
\ No newline at end of file