From be7dbc150a58579d8389cc18e92f9e35f100ca0c Mon Sep 17 00:00:00 2001 From: wbshi168 <154323674+wbshi168@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:18:28 +0800 Subject: [PATCH 1/4] Update index.js --- src/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 97b088521..b7b7ad2db 100644 --- a/src/index.js +++ b/src/index.js @@ -7,17 +7,17 @@ const dockerHub = "https://registry-1.docker.io"; const routes = { // production - "docker.libcuda.so": dockerHub, - "quay.libcuda.so": "https://quay.io", - "gcr.libcuda.so": "https://gcr.io", - "k8s-gcr.libcuda.so": "https://k8s.gcr.io", - "k8s.libcuda.so": "https://registry.k8s.io", - "ghcr.libcuda.so": "https://ghcr.io", - "cloudsmith.libcuda.so": "https://docker.cloudsmith.io", - "ecr.libcuda.so": "https://public.ecr.aws", + "docker.wbshi.top": dockerHub, + "quay.wbshi.top": "https://quay.io", + "gcr.wbshi.top": "https://gcr.io", + "k8s-gcr.wbshi.top": "https://k8s.gcr.io", + "k8s.wbshi.top": "https://registry.k8s.io", + "ghcr.wbshi.top": "https://ghcr.io", + "cloudsmith.wbshi.top": "https://docker.cloudsmith.io", + "ecr.wbshi.top": "https://public.ecr.aws", // staging - "docker-staging.libcuda.so": dockerHub, + "docker-staging.wbshi.top": dockerHub, }; function routeByHosts(host) { From ed47ccafcafd7e67607d249410799e806ec3ef97 Mon Sep 17 00:00:00 2001 From: wbshi168 <154323674+wbshi168@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:19:05 +0800 Subject: [PATCH 2/4] Update wrangler.toml --- wrangler.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wrangler.toml b/wrangler.toml index c3077a0ff..bcb22eb49 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -13,13 +13,13 @@ TARGET_UPSTREAM = "https://registry-1.docker.io" [env.production] name = "cloudflare-docker-proxy" # routes = [ -# { pattern = "docker.libcuda.so", custom_domain = true }, -# { pattern = "quay.libcuda.so", custom_domain = true }, -# { pattern = "gcr.libcuda.so", custom_domain = true }, -# { pattern = "k8s-gcr.libcuda.so", custom_domain = true }, -# { pattern = "k8s.libcuda.so", custom_domain = true }, -# { pattern = "ghcr.libcuda.so", custom_domain = true }, -# { pattern = "cloudsmith.libcuda.so", custom_domain = true }, +# { pattern = "docker.wbshi.top", custom_domain = true }, +# { pattern = "quay.wbshi.top", custom_domain = true }, +# { pattern = "gcr.wbshi.top", custom_domain = true }, +# { pattern = "k8s-gcr.wbshi.top", custom_domain = true }, +# { pattern = "k8s.wbshi.top", custom_domain = true }, +# { pattern = "ghcr.wbshi.top", custom_domain = true }, +# { pattern = "cloudsmith.wbshi.top", custom_domain = true }, # ] [env.production.vars] @@ -28,7 +28,7 @@ TARGET_UPSTREAM = "" [env.staging] name = "cloudflare-docker-proxy-staging" -# route = { pattern = "docker-staging.libcuda.so", custom_domain = true } +# route = { pattern = "docker-staging.wbshi.top", custom_domain = true } [env.staging.vars] MODE = "staging" From 5139fc0eb8ffe215cf2a3759db9d1336f775bd01 Mon Sep 17 00:00:00 2001 From: wbshi168 <154323674+wbshi168@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:41:08 +0800 Subject: [PATCH 3/4] Update index.js --- src/index.js | 64 +++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/index.js b/src/index.js index b7b7ad2db..785a41aae 100644 --- a/src/index.js +++ b/src/index.js @@ -7,17 +7,17 @@ const dockerHub = "https://registry-1.docker.io"; const routes = { // production - "docker.wbshi.top": dockerHub, - "quay.wbshi.top": "https://quay.io", - "gcr.wbshi.top": "https://gcr.io", - "k8s-gcr.wbshi.top": "https://k8s.gcr.io", - "k8s.wbshi.top": "https://registry.k8s.io", - "ghcr.wbshi.top": "https://ghcr.io", - "cloudsmith.wbshi.top": "https://docker.cloudsmith.io", - "ecr.wbshi.top": "https://public.ecr.aws", + ["docker." + CUSTOM_DOMAIN]: dockerHub, + ["quay." + CUSTOM_DOMAIN]: "https://quay.io", + ["gcr." + CUSTOM_DOMAIN]: "https://gcr.io", + ["k8s-gcr." + CUSTOM_DOMAIN]: "https://k8s.gcr.io", + ["k8s." + CUSTOM_DOMAIN]: "https://registry.k8s.io", + ["ghcr." + CUSTOM_DOMAIN]: "https://ghcr.io", + ["cloudsmith." + CUSTOM_DOMAIN]: "https://docker.cloudsmith.io", + ["ecr." + CUSTOM_DOMAIN]: "https://public.ecr.aws", // staging - "docker-staging.wbshi.top": dockerHub, + ["docker-staging." + CUSTOM_DOMAIN]: dockerHub, }; function routeByHosts(host) { @@ -58,24 +58,9 @@ async function handleRequest(request) { redirect: "follow", }); if (resp.status === 401) { - if (MODE == "debug") { - headers.set( - "Www-Authenticate", - `Bearer realm="http://${url.host}/v2/auth",service="cloudflare-docker-proxy"` - ); - } else { - headers.set( - "Www-Authenticate", - `Bearer realm="https://${url.hostname}/v2/auth",service="cloudflare-docker-proxy"` - ); - } - return new Response(JSON.stringify({ message: "UNAUTHORIZED" }), { - status: 401, - headers: headers, - }); - } else { - return resp; + return responseUnauthorized(url); } + return resp; } // get token if (url.pathname == "/v2/auth") { @@ -122,7 +107,11 @@ async function handleRequest(request) { headers: request.headers, redirect: "follow", }); - return await fetch(newReq); + const resp = await fetch(newReq); + if (resp.status == 401) { + return responseUnauthorized(url); + } + return resp; } function parseAuthenticate(authenticateStr) { @@ -147,9 +136,28 @@ async function fetchToken(wwwAuthenticate, scope, authorization) { if (scope) { url.searchParams.set("scope", scope); } - headers = new Headers(); + const headers = new Headers(); if (authorization) { headers.set("Authorization", authorization); } return await fetch(url, { method: "GET", headers: headers }); } + +function responseUnauthorized(url) { + const headers = new(Headers); + if (MODE == "debug") { + headers.set( + "Www-Authenticate", + `Bearer realm="http://${url.host}/v2/auth",service="cloudflare-docker-proxy"` + ); + } else { + headers.set( + "Www-Authenticate", + `Bearer realm="https://${url.hostname}/v2/auth",service="cloudflare-docker-proxy"` + ); + } + return new Response(JSON.stringify({ message: "UNAUTHORIZED" }), { + status: 401, + headers: headers, + }); +} From e77d07ea1c8459b3c9f6a94cd18866325c88aa63 Mon Sep 17 00:00:00 2001 From: wbshi168 <154323674+wbshi168@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:43:44 +0800 Subject: [PATCH 4/4] Update index.js --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 785a41aae..9e2616d43 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ addEventListener("fetch", (event) => { event.respondWith(handleRequest(event.request)); }); -const dockerHub = "https://registry-1.docker.io"; +const dockerHub = "https://hub.docker.com/"; const routes = { // production