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
| const handleRequest = async ({
request
}) => {
let url = new URL(request.url);
let body = await request.text();
try {
body = JSON.parse(body);
body.api_key = '你的 UptimeRobot key'
body = JSON.stringify(body);
} catch (error) {
console.log(error)
}
let response = await fetch('https://api.uptimerobot.com' + url.pathname, {
body: body,
headers: {
'user-agent': 'Mozilla/4.0 MDN Example',
'content-type': 'application/json'
},
method: 'POST', // *GET, POST, PUT, DELETE, etc.
redirect: 'follow', // manual, *follow, error
});
response = new Response(response.body, response);
response.headers.set('Access-Control-Allow-Origin', '*');
response.headers.set('Access-Control-Allow-Methods', '*');
response.headers.set('Access-Control-Allow-Credentials', 'true');
response.headers.set('Access-Control-Allow-Headers', 'Content-Type,Access-Token');
response.headers.set('Access-Control-Expose-Headers', '*');
let json = await response.text()
try {
json = JSON.parse(json)
// 隐藏域名
json.monitors = json.monitors.map(site => {
site.url = undefined
return site
});
json = JSON.stringify(json)
} catch (error) {}
return new Response(json, response)
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});
|