目前用的是这个代码 访问为 https://xxxxx.com/bot131232115:AAF33xWSkdTQ231231312312XyoJ6b5kCGMvEv0/sendMessage?chat_id=2342432348&text=22282H
我想改为加路径模式 https://xxxxx.com/tg/bot131232115:AAF33xWSkdTQ231231312312XyoJ6b5kCGMvEv0/sendMessage?chat_id=2342432348&text=22282H
路由里面改了也不行 https://xxxxx.com/tg/*
请问代码需要怎么修改?
- const whitelist = ["/bot131232115:"];
- 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;
- }
复制代码
|