Giter VIP home page Giter VIP logo

cf-page-func-proxy's Issues

如果需要使用单双日实现访问不同的域名,这样做可以吗

RT

代码如下:

const day1 = 'app0.herokuapp.com'
const day2 = 'app1.herokuapp.com'

export default {
    async fetch(request, env) {
      let url = new URL(request.url)
      if (url.pathname.startsWith("/")) {
        let day = new Date().getDay()
        if (day === 0) {
          host = day1
        } else {
          host = day2
        }
        url.hostname=host
        let response = new Response(url, request)
        return response(new_request)
      }
      return env.ASSETS.fetch(request);
    }
  };

多台服务器负载均衡方法

export default {
	async fetch(request, env) {
		const cars = [
			"app1.example.com", 
			"app2.example.com", 
			"app3.example.com", 
			"app4.example.com", 
			"app5.example.com"
		];
		let host = cars[Math.floor(Math.random() * cars.length)];	//随机选择VPS
		//let host = cars[new Date().getDate() % cars.length];		//每天自动更换VPS
		
		let url = new URL(request.url);
		if (url.pathname.startsWith('/')) {
			url.hostname = host;
			let new_request = new Request(url,request);
			return fetch(new_request);
		}
		return env.ASSETS.fetch(request);
	}
};

请教pages执行原来workers代码的问题

下面是在workers验证过可以执行的代码,用于获取用户真实IP的脚本源码,目的是用户访问这个workers的网址就可以报告用户端的出口ip地址

addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});

/**

  • Return user real ip as response in plain text.
  • @param {Request} request
  • @returns {Promise}
    */
    async function handleRequest(request) {
    const clientIP = request.headers.get("CF-Connecting-IP")
    return new Response(clientIP);
    }

但是上面这段代码按照你这个项目的方法,替代了_worker.js文件里面的所有代码成为上面的代码,在pages上一部署就报告错误,我由于对这些代码不熟悉,能否麻烦你帮忙看看是否在pages上部署要做相应的代码更改?

非常感谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.