关于下载流量的问题
Closed this issue · 6 comments
jooooock commented
SpringZhang1978 commented
大佬 给个部署文档吧 自己玩玩 感谢
jooooock commented
最近正在研究cloudflare,到时候看看cloudflare和deno deploy哪个好用
marsbaiyun commented
哈哈,别处引流过来的,这个会存在账号封禁的问题么?
jooooock commented
哈哈,别处引流过来的,这个会存在账号封禁的问题么?
不确定,目前遇到这个接口被限制之后,公众号的其他功能正常,但不确定被禁时间长了之后会不会有影响
jooooock commented
目前研究结果是:没必要完全迁移到CF,但是可以使用CF搭建代理节点,分散下载流量。
当前共搭建了6个代理节点,这些节点全部部署在Deno Deploy上面。
wechat-article-exporter/config/index.ts
Lines 20 to 30 in ae7e6c7
Deno Deploy 代理节点代码
function error(msg: Error | string) {
return new Response(msg instanceof Error ? msg.message : msg, {
status: 403,
});
}
async function wfetch(url: string, opt: Record<string, string> = {}) {
if (!opt) {
opt = {};
}
const options: Record<string, any> = {
method: "GET",
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36",
},
};
if (opt.referer) {
options.headers["Referer"] = opt.referer;
}
return await fetch(url, options);
}
Deno.serve(async (req: Request) => {
if (req.method.toLowerCase() !== "get") {
return error("Method not allowed");
}
const origin = req.headers.get("origin")!;
const { searchParams } = new URL(req.url);
let url = searchParams.get("url");
if (!url) {
return error("url cannot empty");
}
url = decodeURIComponent(url);
console.log("proxy url:", url);
if (!/^https?:\/\//.test(url)) {
return error("url not valid");
}
const response = await wfetch(url);
return new Response(response.body, {
headers: {
"Access-Control-Allow-Origin": origin,
"Content-Type": response.headers.get("Content-Type")!,
},
});
});
CF代理节点代码
function error(msg) {
return new Response(msg instanceof Error ? msg.message : msg, {
status: 403,
});
}
async function wfetch(url, opt = {}) {
if (!opt) {
opt = {};
}
const options = {
method: "GET",
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36",
},
};
if (opt.referer) {
options.headers["Referer"] = opt.referer;
}
return await fetch(url, options);
}
export default {
async fetch(req, env, ctx) {
if (req.method.toLowerCase() !== "get") {
return error("Method not allowed");
}
const origin = req.headers.get("origin");
const { searchParams } = new URL(req.url);
let url = searchParams.get("url");
if (!url) {
return error("url cannot empty");
}
url = decodeURIComponent(url);
console.log("proxy url:", url);
if (!/^https?:\/\//.test(url)) {
return error("url not valid");
}
const response = await wfetch(url);
return new Response(response.body, {
headers: {
"Access-Control-Allow-Origin": origin,
"Content-Type": response.headers.get("Content-Type"),
},
});
},
};
欢迎大家搭建自己的代理节点,然后可以提pr合并进代码中使用。
jooooock commented
大佬 给个部署文档吧 自己玩玩 感谢
@SpringZhang1978 已更新私有部署文档