Skip to content

Instantly share code, notes, and snippets.

@dishengai
dishengai / worker.js
Created December 20, 2023 07:53 — forked from s1ntoneli/worker.js
Cloudflare worker,简单转发实现国内访问 ChatGPT
const TELEGRAPH_URL = 'https://api.openai.com';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url);
url.host = TELEGRAPH_URL.replace(/^https?:\/\//, '');
// Website you intended to retrieve for users.
const upstream = 'api.openai.com'
// Custom pathname for the upstream website.
const upstream_path = '/'
// Website you intended to retrieve for users using mobile devices.
const upstream_mobile = upstream
// Countries and regions where you wish to suspend your service.