请选择一篇笔记
●
就绪
代理地址?target=完整Gitee地址。
export default {
async fetch(req) {
const t = new URL(req.url).searchParams.get('target');
if (!t) return new Response('missing target', { status: 400 });
const h = new Headers();
const a = req.headers.get('authorization');
if (a) h.set('authorization', a);
if (req.headers.get('content-type')) h.set('content-type', req.headers.get('content-type'));
const m = req.method === 'GET' ? 'GET' : req.method;
const r = await fetch(t, {
method: m,
headers: h,
body: m === 'GET' ? undefined : await req.text()
});
const nh = new Headers();
nh.set('access-control-allow-origin', '*');
['content-type'].forEach(k => { const v = r.headers.get(k); if (v) nh.set(k, v); });
return new Response(r.body, { status: r.status, headers: nh });
}
}