Cloudflare Pages多账户反代代码应用

 



拯救被墙的workers反代:Heroku三合一共存协议项目发布,简析三种设置pages反代方式,workers反代与pages反代套自定义域名最详细教程,直连地址,反代地址,自选域名地址大测试

操作注意点:

1、无论使用“项目代码拉取模式”、“文件夹目录上传模式”还是“ZIP压缩上传模式”,请把文件名称一律改为_worker.js(js格式),视频教程中已演示

2、修改_worker.js中的url.hostname="app.example.com"中的app.example.com为你要反代的网址

3、使用本地上传模式时,你可能犹豫是先改js文件名,还是先改文件内的代码?无所谓先后,随意

4、以下三个多账户代码取自网络上workers反代的多账户写法,并参考Pages单账户反代代码项目

建议:比如heroku双账号,一般选择单双日轮换,可分别用两个账号的应用程序名(代理协议、PATH路径、UUID保持一致),单双号天分别执行,那一个月就有550+550小时,heroku一个账户默认每月最多免费使用550小时

以下代码你也可以放置在Github上,只要在Github上更改网址,最终的pages反代内容会自动同步你的更改。。

CloudFlare Pages单双日轮换反代代码

export default {
    async fetch(request, env) {
      const SingleDay = 'app0.example.com'
      const DoubleDay = 'app1.example.com'
      let host = ''
      let nd = new Date();
      if (nd.getDate()%2) {
          host = SingleDay
      } else {
          host = DoubleDay
      }
      let url = new URL(request.url);
      if (url.pathname.startsWith('/')) {
        url.hostname=host;
        let new_request=new Request(url,request);
        return fetch(new_request);
      }
      // Otherwise, serve the static assets.
      return env.ASSETS.fetch(request);
    }
  };
 CloudFlare Pages每五天轮换一遍式反代代码
export default {
    async fetch(request, env) {
      const Day0 = 'app0.example.com'
      const Day1 = 'app1.example.com'
      const Day2 = 'app2.example.com'
      const Day3 = 'app3.example.com'
      const Day4 = 'app4.example.com'
      let host = ''
      let nd = new Date();
        let day = nd.getDate() % 5;
        if (day === 0) {
            host = Day0
        } else if (day === 1) {
            host = Day1
        } else if (day === 2) {
            host = Day2
        } else if (day === 3){
            host = Day3
        } else if (day === 4){
            host = Day4
        } else {
            host = Day1
        }

      let url = new URL(request.url);
      if (url.pathname.startsWith('/')) {
        url.hostname=host;
        let new_request=new Request(url,request);
        return fetch(new_request);
      }
      // Otherwise, serve the static assets.
      return env.ASSETS.fetch(request);
    }
  };
CloudFlare Pages一周轮换反代代码
export default {
    async fetch(request, env) {
      const Day0 = 'app0.example.com'
      const Day1 = 'app1.example.com'
      const Day2 = 'app2.example.com'
      const Day3 = 'app3.example.com'
      const Day4 = 'app4.example.com'
      const Day5 = 'app5.example.com'
      const Day6 = 'app6.example.com'
      let host = ''
      let nd = new Date();
        let day = nd.getDay();
        if (day === 0) {
            host = Day0
        } else if (day === 1) {
            host = Day1
        } else if (day === 2) {
            host = Day2
        } else if (day === 3){
            host = Day3
        } else if (day === 4) {
            host = Day4
        } else if (day === 5) {
            host = Day5
        } else if (day === 6) {
            host = Day6
        } else {
            host = Day1
        }

      let url = new URL(request.url);
      if (url.pathname.startsWith('/')) {
        url.hostname=host;
        let new_request=new Request(url,request);
        return fetch(new_request);
      }
      // Otherwise, serve the static assets.
      return env.ASSETS.fetch(request);
    }
  };

发表评论

0 评论