Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you convert this code to work for cloudflare pages? #1

Open
egg1234 opened this issue Aug 27, 2022 · 4 comments
Open

Would you convert this code to work for cloudflare pages? #1

egg1234 opened this issue Aug 27, 2022 · 4 comments

Comments

@egg1234
Copy link

egg1234 commented Aug 27, 2022

Would you convert this code to work for cloudflare pages?

Thank you!

@JimmyTinsley
Copy link
Owner

JimmyTinsley commented Sep 12, 2022

Would you convert this code to work for cloudflare pages?

Thank you!

Thanks for your interest! @egg1234

I am not pretty clear about "work for cloudflare pages".
Does it mean by deploying a webpage using cloudflare pages, and when you access the webpage in browser, the webpage tells you the source ip address?

@egg1234
Copy link
Author

egg1234 commented Sep 12, 2022

@JimmyTinsley 谢谢你的回复!
就是你理解的意思,希望把 workers.js 的代码修改成CF-pages可以部署的形式,因为现在的 workers.js 代码部署在CF-pages是不能工作的,我不知道为什么。
如果你修改完成后,可以建立一个新的repo,按我搜索整个internet及github,能够在pages部署这个回显用户ip的代码应该是首发,暂时中文及英文都没有
在CF-pages部署完后,举例的工作方式应该是 curl https://myip.pages.dev 就可以回显用户的出口ip地址

@JimmyTinsley
Copy link
Owner

@egg1234 我研究下pages文档看看

@egg1234
Copy link
Author

egg1234 commented Sep 13, 2022

@JimmyTinsley 下面是CF-pages能够部署并工作的_worker.js代码的例子,如果有用你就参考一下,它的确与达到同样功能的CF-workers的_worker.js代码有一些差别,但我是不明白它与CF-workers要求的_worker.js代码格式的差别是什么

export default {
async fetch(request, env) {
let url = new URL(request.url);
if (url.pathname.startsWith('/')) {
url.hostname="www.myname.com";
let new_request=new Request(url,request);
return fetch(new_request);
}
// Otherwise, serve the static assets.
return env.ASSETS.fetch(request);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants