cf workers反代Tg Bot Api
•默认分类
4067
0
const whitelist = ["/bot12345:"];
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;
}
把第一行的12345替换成你的机器人token前面的数字,其它不动
设置一个用来反代的域名前缀解析,并打开彩色云朵,解析地址为:2.2.2.2,
然后添加workers的路由,指向这个workers。