add reverse proxy templates
This commit is contained in:
commit
21432d65a2
22
reverse-proxy/domins.js
Normal file
22
reverse-proxy/domins.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// 泛域名反代
|
||||||
|
// 在环境变量中添加 @域名前缀,例如@github=https://github.com/,则访问https://github.xxxx.xxx/时,实际访问https://github.com/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async fetch(request, env) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
new URL(request.url)
|
||||||
|
let name = url.hostname.split('.')[0];
|
||||||
|
let target = env['@' + name];
|
||||||
|
if (!target) {
|
||||||
|
return new Response('Not Found', {
|
||||||
|
status: 404
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return fetch(new Request(target + url.pathname + url.search, {
|
||||||
|
body: request.body,
|
||||||
|
headers: request.headers,
|
||||||
|
method: request.method,
|
||||||
|
redirect: request.redirect
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
31
reverse-proxy/github-releases.js
Normal file
31
reverse-proxy/github-releases.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
export default {
|
||||||
|
async fetch(request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const { hostname, pathname, search } = url;
|
||||||
|
if (checkUrl(pathname)) {
|
||||||
|
return fetch(new Request("https://github.com" + pathname + search, {
|
||||||
|
body: request.body,
|
||||||
|
headers: request.headers,
|
||||||
|
method: request.method,
|
||||||
|
redirect: request.redirect
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
let tip = `GitHub 下载代理,支持 releases、archive、tags、raw 等。
|
||||||
|
|
||||||
|
使用方法:将 Github 原链接中的 【github.com】 改为 【${hostname}】。
|
||||||
|
如:【https://github.com/a/a/releases】改为【https://${hostname}/a/a/releases】。`
|
||||||
|
return new Response(tip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function checkUrl(u) {
|
||||||
|
const exp1 = "/.+?\/.+?\/(?:releases|archive|tags).*"
|
||||||
|
const exp2 = "/.+?\/.+?\/raw\/.*"
|
||||||
|
for (let ind of [exp1, exp2]) {
|
||||||
|
if (u.search(ind) === 0) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
12
reverse-proxy/normal.js
Normal file
12
reverse-proxy/normal.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export default {
|
||||||
|
async fetch(request) {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const { pathname, search } = url;
|
||||||
|
return fetch(new Request("https://github.com" + pathname + search, {
|
||||||
|
body: request.body,
|
||||||
|
headers: request.headers,
|
||||||
|
method: request.method,
|
||||||
|
redirect: request.redirect
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user