mirror of https://github.com/yuxian158/check.git
张洛
3 years ago
1 changed files with 0 additions and 25 deletions
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
const whitelist = ["/bot"]; |
||||
const tg_host = "api.telegram.org"; |
||||
addEventListener('fetch', event =>{ |
||||
event.respondWith(handleRequest(event.request)) |
||||
}) |
||||
function validate(path) { |
||||
for (var i = 0; i < whitelist.length; i++) { |
||||
if (path.startsWith(whitelist[i])) return true; |
||||
} |
||||
return false; |
||||
} |
||||
async function handleRequest(request) { |
||||
var u = new URL(request.url); |
||||
u.host = tg_host; |
||||
if (!validate(u.pathname)) return new Response('Unauthorized', { |
||||
status: 403 |
||||
}); |
||||
var req = new Request(u, { |
||||
method: request.method, |
||||
headers: request.headers, |
||||
body: request.body |
||||
}); |
||||
const result = await fetch(req); |
||||
return result; |
||||
} |
Loading…
Reference in new issue