Skip to content

Commit

Permalink
添加接口反代说明;
Browse files Browse the repository at this point in the history
  • Loading branch information
yb committed Feb 18, 2021
1 parent 4d3fd33 commit b72a263
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# uptime-status
A uptime status dashboard based on UptimeRobot API

一个基于 UptimeRobot API 的在线状态面板

An uptime status dashboard based on UptimeRobot API

------

### 基于 Cloudflare Workers 搭建 UptimeRobot API 代理,以解决官网 API 跨域问题

Build an UptimeRobot API proxy based on **Cloudflare Workers** to solve the cross-domain issue of official API

```
const handleRequest = async ({ request }) => {
let url = new URL(request.url);
let response = await fetch('https://api.uptimerobot.com' + url.pathname, request);
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', '*');
return response;
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});
```

修改 `config.js` 中的 `ApiDomian` 为你的域名;

Modify `ApiDomian` in `config.js` to your domain;
1 change: 1 addition & 0 deletions public/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ window.Config = {
// UptimeRobot Api 域名
// 只需填写域名部分,默认为官网域名
// 因官网 API 时不时的会 CROS 报错,可填自定义反代域名
// 详见 https://github.com/yb/uptime-status/ 说明
ApiDomain: 'api.uptimerobot.com',

// UptimeRobot Api Keys
Expand Down

0 comments on commit b72a263

Please sign in to comment.