MCPcopy Create free account
hub / github.com/adysec/mirror / proxyTextRequest

Function proxyTextRequest

worker.js:106–121  ·  view source on GitHub ↗

* 代理文本文件(如 tailscale.list)并替换内部链接

(url, base, replacePrefix)

Source from the content-addressed store, hash-verified

104 * 代理文本文件(如 tailscale.list)并替换内部链接
105 */
106async function proxyTextRequest(url, base, replacePrefix) {
107 try {
108 const targetUrl = base + url.pathname.replace(replacePrefix, '');
109 const response = await fetch(targetUrl);
110
111 if (url.pathname.endsWith('.list')) {
112 let body = await response.text();
113 body = body.replace(new RegExp(base, 'g'), `${url.origin}${replacePrefix}`);
114 return new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
115 }
116
117 return new Response(response.body, { headers: response.headers });
118 } catch (err) {
119 return new Response('Error fetching text file: ' + err.message, { status: 500 });
120 }
121}
122
123/**
124 * 代理二进制文件(如 PyPI 资源)

Callers 1

handleRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected