To create your first Worker using the Cloudflare dashboard:
- Log in to the Cloudflare dashboard and select your account.
- Select Workers & Pages > Create application.
- Select Create Worker > Deploy.
要使用 Cloudflare 仪表板创建您的第一个 Worker:
- 登录 Cloudflare 仪表板并选择您的帐户。
- 选择 Workers 和 Pages > 创建应用程序。
- 选择 创建 Worker > 部署。
Copy the following code to replace the original worker.js
code, and then click Deploy.
addEventListener('fetch', (event) => {
const headers = event.request.headers
const url = new URL(event.request.url)
url.hostname = 'generativelanguage.googleapis.com'
url.protocol = 'https'
const request = new Request(url, event.request)
return event.respondWith(fetch(request))
})
复制以下代码替换原有的 worker.js
代码,然后点击 部署。
addEventListener('fetch', (event) => {
const headers = event.request.headers
const url = new URL(event.request.url)
url.hostname = 'generativelanguage.googleapis.com'
url.protocol = 'https'
const request = new Request(url, event.request)
return event.respondWith(fetch(request))
})
Since the workers.dev
domain can not be accessed normally in some countries, you can solve this problem by setting a custom domain.
- Select Workers & Pages > [Your Worker Script].
- Select Settings > Triggers.
- Choose Add Custom Domain.
由于在部分国家无法正常访问 workers.dev
域名,可以通过设置自定义域名来解决这个问题。
- 选择 Workers 和 Pages > [您的 Worker 脚本]。
- 选择 设置 > 触发器。
- 选择 添加自定义域。