Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest authored May 27, 2024
1 parent a6100ee commit 8f14999
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,47 @@ export default {
* @param {Request} request
* @returns {Response}
*/
async fetch({ url, method, headers }) {
async fetch({ url: urlStr, method, headers }) {
if (headers.get("origin") == "https://rewatch.to")
return new Response("Blocked", { status: 403 });
if (method == "OPTIONS")
return new Response("", {
headers: { "Access-Control-Allow-Origin": "*" },
});
if (method == "GET") {
const locationSpecified = new URL(url).searchParams.get("url");
if (!locationSpecified)
return new Response("No url to get specified", { status: 400 });
const locationResponse = await fetch(locationSpecified, {
headers: { "User-Agent": "github.com/SkyblockClient (mart, proxy)" },
});
const response = new Response(locationResponse.body, {
status: locationResponse.status,
headers: { "Access-Control-Allow-Origin": "*" },
});
return response;
const url = new URL(urlStr);
if (url.pathname != "/")
return new Response("Not found", { status: 404 });
switch (method) {
case "OPTIONS":
return new Response("", {
headers: { "access-control-allow-origin": "*" }
});
case "GET":
const locationSpecified = url.searchParams.get("url");
if (!locationSpecified)
return new Response("No url to get specified", { status: 400 });
const qHeaders = {
"user-agent": "github.com/SkyblockClient (mart, proxy)"
};
const qEtag = headers.get("If-None-Match");
if (qEtag)
qHeaders["if-none-match"] = qEtag;
const locationResponse = await fetch(locationSpecified, {
headers: qHeaders
});
if (locationResponse.status == 304)
return new Response("", { status: 304 });
const aHeaders = {
"access-control-allow-origin": "*"
};
const aEtag = locationResponse.headers.get("etag");
if (aEtag)
aHeaders["etag"] = aEtag;
const response = new Response(locationResponse.body, {
status: locationResponse.status,
headers: aHeaders
});
return response;
default:
return new Response(`Method ${method} is not supported`, {
status: 405
});
}
return new Response(`Method ${method} is not supported`, { status: 405 });
},
}
};

0 comments on commit 8f14999

Please sign in to comment.