xytom / cf-page-func-proxy Goto Github PK
View Code? Open in Web Editor NEWUse Cloudflare Pages Functions as a reverse proxy with custom domain support.
License: Apache License 2.0
Use Cloudflare Pages Functions as a reverse proxy with custom domain support.
License: Apache License 2.0
在cloudflare自定义域名中,没有“开始cname设置”选项
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);
}
};
下面是在workers验证过可以执行的代码,用于获取用户真实IP的脚本源码,目的是用户访问这个workers的网址就可以报告用户端的出口ip地址
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
/**
但是上面这段代码按照你这个项目的方法,替代了_worker.js文件里面的所有代码成为上面的代码,在pages上一部署就报告错误,我由于对这些代码不熟悉,能否麻烦你帮忙看看是否在pages上部署要做相应的代码更改?
非常感谢!
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);
}
};
这个网页为什么只能反代首页?点击其他就跳转原站?
https://www.websiteplanet.com/
感谢
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.