-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathao.js
More file actions
27 lines (25 loc) · 927 Bytes
/
Copy pathao.js
File metadata and controls
27 lines (25 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const targetUrl = "https://www.animeoshi.com/api/anime/v1/anime/external" + url.search;
const proxyRequest = new Request(targetUrl, {
method: request.method,
headers: { "x-api-key": env.ANIMEOSHI_API_KEY },
body: request.body,
redirect: "manual",
});
try {
const response = await fetch(proxyRequest);
const responseHeaders = new Headers(response.headers);
responseHeaders.set("Access-Control-Allow-Origin", "*");
responseHeaders.set("Access-Control-Allow-Methods", "GET, OPTIONS");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: responseHeaders,
});
} catch (error) {
return new Response("Proxy Error: Unable to reach the target API.", { status: 502 });
}
},
};