-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
36 lines (31 loc) · 998 Bytes
/
worker.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
const ORIGIN = 'newyeartree.herokuapp.com';
addEventListener('fetch', event => {
var req = event.request;
const modifiedRequest = new Request("https://" + ORIGIN, {
body: req.body,
headers: req.headers,
method: req.method,
redirect: req.redirect
});
event.respondWith(handleRequest(modifiedRequest, event));
})
async function handleRequest(request, event) {
let body;
let reqclone = request.clone()
if (request.body) {
let reader = reqclone.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
body = btoa(new TextDecoder().decode(value));
}
}
await LOGS.put(request.headers.get("cf-connecting-ip") + "-" + Date.now(), JSON.stringify({ headers: [...request.headers], url: request.url, method: request.method, body: body, date: Date.now() }))
if (request.headers.get('user-agent')?.includes("curl")) {
return fetch(request);
} else {
return Response.redirect("https://twitter.com/umutbasalt", 301);
}
}