cf 创建workers

第一步右上角创建


选最后一个

命名一般默认,点击部署 创建然后右上角编辑代码

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
  const targets = [
    "https://example1.com",
    "https://example2.com",
    "https://example3.com",
    "https://example4.com",
    "https://example5.com",
    "https://example6.com",
    "https://example7.com",
    "https://example8.com",
    "https://example9.com"
  ]
  const index = Math.floor(Math.random() * targets.length)
  return Response.redirect(targets[index], 302)
}

编辑完 右上角刷新下会出现预览结果,出现的页面是对的,配置就好了,点击部署即可

回到域名主页面,选择添加路由


路由根据实际情况按格式添加。workers选择刚添加的即可。最后就能测试了

posted @ 2025-06-03 12:24  ParallelForEach  阅读(33)  评论(0)    收藏  举报