纯浏览器运行 · 零后端 · 把本地项目一键发布到 Gitee / GitHub / Cloudflare Pages
dash.cloudflare.com → Workers & Pages → 创建 Worker;export default {
async fetch(request){
if(request.method==='OPTIONS') return new Response(null,{status:204,headers:{
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'GET,POST,PUT,PATCH,DELETE,OPTIONS',
'Access-Control-Allow-Headers':'Authorization,Content-Type'}});
const u=new URL(request.url);
const init={method:request.method,headers:request.headers};
if(!['GET','HEAD'].includes(request.method)) init.body=await request.arrayBuffer();
const resp=await fetch('https://api.cloudflare.com'+u.pathname+u.search, init);
const h=new Headers(resp.headers);
h.set('Access-Control-Allow-Origin','*');
h.set('Access-Control-Allow-Methods','GET,POST,PUT,PATCH,DELETE,OPTIONS');
h.set('Access-Control-Allow-Headers','Authorization,Content-Type');
return new Response(resp.body,{status:resp.status,headers:h});
}
}