Skip to content

Commit

Permalink
fix: fix cloudflare home
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 29, 2023
1 parent 90df941 commit db188a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cloudflare/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<link rel="icon" type="image/svg+xml" href="https://gitee.com/adams549659584/go-proxy-bingai/raw/master/frontend/public/img/logo.svg" />
<link rel="icon" type="image/svg+xml" href="/github/frontend/public/img/logo.svg" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<link rel="apple-touch-icon" href="https://gitee.com/adams549659584/go-proxy-bingai/raw/master/frontend/public/img/pwa/logo-192.png">
<link rel="apple-touch-icon" href="/github/frontend/public/img/pwa/logo-192.png">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
<meta name="referrer" content="origin-when-cross-origin" />
Expand Down Expand Up @@ -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">
<div class="mx-auto max-w-3xl">
<div class="flex justify-center">
<img src="https://gitee.com/adams549659584/go-proxy-bingai/raw/master/frontend/public/img/logo.svg" class="h-24" alt="BingAI" />
<img src="/github/frontend/public/img/logo.svg" class="h-24" alt="BingAI" />
</div>
<div class="mt-6 text-center text-3xl text-gray-600">聊天服务器已部署完成</div>
<div class="divide-y divide-gray-300/50">
Expand Down
23 changes: 18 additions & 5 deletions cloudflare/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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);

Expand Down

0 comments on commit db188a6

Please sign in to comment.