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

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

Open
egg1234 opened this issue Jul 18, 2022 · 0 comments
Open

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

egg1234 opened this issue Jul 18, 2022 · 0 comments

Comments

@egg1234
Copy link

egg1234 commented Jul 18, 2022

下面是在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上部署要做相应的代码更改?

非常感谢!

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

1 participant