Download scripts/deploy/cloudflare-worker-api.js from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 962 Bytes
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/scripts/deploy/cloudflare-worker-api.js
- Command line
-
hf download hf://spaces/binhugg3/admin/scripts/deploy/cloudflare-worker-api.js
-
curl -L -o cloudflare-worker-api.js https://huggingface.co/spaces/binhugg3/admin/resolve/main/scripts/deploy/cloudflare-worker-api.js
962 Bytes
| // Cloudflare Worker - API 反向代理 | |
| // 目标:bin-api.hanbin666.top → binhugg2-api.hf.space | |
| // 部署方式:Cloudflare Dashboard → Workers & Pages → Create Worker → 粘贴此代码 | |
| // 路由绑定:bin-api.hanbin666.top/* | |
| export default { | |
| async fetch(request) { | |
| const url = new URL(request.url); | |
| // 替换目标域名 | |
| url.hostname = "binhugg2-api.hf.space"; | |
| url.port = "443"; | |
| url.protocol = "https:"; | |
| const newRequest = new Request(url.toString(), { | |
| method: request.method, | |
| headers: request.headers, | |
| body: ["GET", "HEAD"].includes(request.method) ? undefined : request.body, | |
| redirect: "follow", | |
| }); | |
| const response = await fetch(newRequest); | |
| // 透传响应,保留原始 headers | |
| const newResponse = new Response(response.body, { | |
| status: response.status, | |
| statusText: response.statusText, | |
| headers: response.headers, | |
| }); | |
| return newResponse; | |
| }, | |
| }; | |