This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (46 loc) · 1.6 KB
/
script.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 503 })
)
);
});
/**
* Many more examples available at:
* https://developers.cloudflare.com/workers/examples
* @param {Request} request
* @returns {Promise<Response>}
*/
async function handleRequest(request) {
const url = new URL(request.url);
url.host = "stats.uptimerobot.com";
const { pathname } = url;
if ( pathname.startsWith("/3YyVnsprMP") ) {
return Response.redirect("https://status.mindhunter.info/", 302)
}
const req = new Request(request);
req.headers.set("Host", "stats.uptimerobot.com");
if (pathname.startsWith("/api") || pathname.startsWith("/assets")) {
return fetch(url.toString(), req);
}
// url.host = "status.mindhunter.info";
url.pathname = "/3YyVnsprMP" + pathname;
const root = await fetch(url.toString(), req);
const text = await root.text();
const newText = text
.replaceAll("stats.uptimerobot.com", "status.mindhunter.info");
return new Response(newText, root);
// Example code
// if (pathname.startsWith("/api")) {
// return new Response(JSON.stringify({ pathname }), {
// headers: { "Content-Type": "application/json" },
// });
// }
// if (pathname.startsWith("/status")) {
// const httpStatusCode = Number(pathname.split("/")[2]);
// return Number.isInteger(httpStatusCode)
// ? fetch("https://http.cat/" + httpStatusCode)
// : new Response("That's not a valid HTTP status code.");
// }
// return fetch("https://welcome.developers.workers.dev");
}