-
Notifications
You must be signed in to change notification settings - Fork 7
/
worker.js
32 lines (26 loc) · 867 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
addEventListener('fetch', event => {
event.respondWith(proxy(event));
});
async function proxy(event) {
const getReqHeader = (key) => event.request.headers.get(key);
let url = new URL(event.request.url);
url.hostname = "disqus.com";
let parameter = {
headers: {
'Host': 'disqus.com',
'User-Agent': getReqHeader("User-Agent"),
'Accept': getReqHeader("Accept"),
'Accept-Language': getReqHeader("Accept-Language"),
'Accept-Encoding': getReqHeader("Accept-Encoding"),
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0'
}
};
if (event.request.headers.has("Referer")) {
parameter.headers.Referer = getReqHeader("Referer");
}
if (event.request.headers.has("Origin")) {
parameter.headers.Origin = getReqHeader("Origin");
}
return fetch(new Request(url, event.request), parameter);
}