diff --git a/cloudflare/index.html b/cloudflare/index.html index d6df026..821f4b0 100644 --- a/cloudflare/index.html +++ b/cloudflare/index.html @@ -3,9 +3,9 @@ - + - + @@ -41,7 +41,7 @@ class="relative bg-white px-6 pb-8 pt-10 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-lg sm:rounded-lg sm:px-10 lg:max-w-3xl">
- BingAI + BingAI
聊天服务器已部署完成
diff --git a/cloudflare/worker.js b/cloudflare/worker.js index 5e80008..2ba5aee 100644 --- a/cloudflare/worker.js +++ b/cloudflare/worker.js @@ -70,10 +70,22 @@ const getRandomIP = () => { return randomIP; }; -const home = async () => { - const res = await fetch('https://raw.githubusercontent.com/adams549659584/go-proxy-bingai/master/cloudflare/index.html'); +/** + * home + * @param {string} pathname + * @returns + */ +const home = async (pathname) => { + let url = `https://raw.githubusercontent.com/adams549659584/go-proxy-bingai/master/cloudflare/index.html`; + // if (pathname.startsWith('/github/')) { + if (pathname.indexOf('/github/') === 0) { + url = pathname.replace('/github/', 'https://raw.githubusercontent.com/adams549659584/go-proxy-bingai/master/'); + } + const res = await fetch(url); const newRes = new Response(res.body, res); - newRes.headers.set('content-type', 'text/html; charset=utf-8'); + if (pathname === '/') { + newRes.headers.set('content-type', 'text/html; charset=utf-8'); + } return newRes; }; @@ -87,8 +99,9 @@ export default { */ async fetch(request, env, ctx) { const currentUrl = new URL(request.url); - if (currentUrl.pathname === '/') { - return home(); + // if (currentUrl.pathname === '/' || currentUrl.pathname.startsWith('/github/')) { + if (currentUrl.pathname === '/' || currentUrl.pathname.indexOf('/github/') === 0) { + return home(currentUrl.pathname); } const targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search);