Create shikimori-proxy.ts

This commit is contained in:
2025-05-12 14:23:48 +05:00
committed by GitHub
parent 4abc129fd3
commit 3dcbb7d406

View File

@@ -0,0 +1,39 @@
import { serve } from "https://deno.land/std@0.140.0/http/server.ts";
serve(async (req) => {
const url = new URL(req.url);
const search = url.searchParams.get("search");
const year = url.searchParams.get("year");
if (!search) {
return new Response("Missing search param", { status: 400 });
}
const targetUrl = `https://shikimori.one/api/animes?search=${encodeURIComponent(search)}&limit=1${year ? `&year=${year}` : ""}`;
try {
const shikiRes = await fetch(targetUrl, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Accept": "application/json"
}
});
const data = await shikiRes.text();
return new Response(data, {
status: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
});
} catch (err) {
return new Response(JSON.stringify({ error: "Shikimori fetch failed" }), {
status: 500,
headers: {
"Content-Type": "application/json"
}
});
}
});