Delivery_robot / cloudflare_worker.js
minhnghiem32131024429
Deploy delivery robot app
5e8b911
Raw
History Blame Contribute Delete
878 Bytes
// Deploy this as a Cloudflare Worker.
// It proxies all requests to api.telegram.org.
//
// Steps:
// 1. Go to https://dash.cloudflare.com → Workers & Pages → Create Worker
// 2. Paste this code, click Deploy
// 3. Copy the worker URL (e.g. https://tg-proxy.yourname.workers.dev)
// 4. Add TELEGRAM_PROXY_URL=https://tg-proxy.yourname.workers.dev
// to HuggingFace Spaces secrets
export default {
async fetch(request) {
const url = new URL(request.url);
const target = new URL("https://api.telegram.org");
target.pathname = url.pathname;
target.search = url.search;
const proxied = new Request(target.toString(), {
method: request.method,
headers: request.headers,
body: request.method !== "GET" && request.method !== "HEAD"
? request.body : undefined,
});
return fetch(proxied);
},
};