diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml deleted file mode 100644 index 1cd233c..0000000 --- a/.github/workflows/stage.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Deploy to Cloudflare Workers(Staging) - -on: - pull_request_target: - paths-ignore: - - '**.md' - repository_dispatch: - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - name: Build & Deploy - steps: - - uses: actions/checkout@v4 - - name: Publish - uses: cloudflare/wrangler-action@v3 - env: - CUSTOM_DOMAIN: ${{ secrets.CUSTOM_DOMAIN || 'libcuda.so' }} - with: - apiToken: ${{ secrets.CF_API_TOKEN }} - accountId: ${{secrets.CF_ACCOUNT_ID}} - vars: - CUSTOM_DOMAIN - command: deploy --env staging --minify src/index.js - environment: staging \ No newline at end of file diff --git a/src/index.js b/src/index.js index 785a41a..a97a738 100644 --- a/src/index.js +++ b/src/index.js @@ -105,12 +105,22 @@ async function handleRequest(request) { const newReq = new Request(newUrl, { method: request.method, headers: request.headers, - redirect: "follow", + // don't follow redirect to dockerhub blob upstream + redirect: isDockerHub ? "manual" : "follow", }); const resp = await fetch(newReq); if (resp.status == 401) { return responseUnauthorized(url); } + // handle dockerhub blob redirect manually + if (isDockerHub && resp.status == 307) { + const location = new URL(resp.headers.get("Location")); + const redirectResp = await fetch(location.toString(), { + method: "GET", + redirect: "follow", + }); + return redirectResp; + } return resp; } diff --git a/wrangler.toml b/wrangler.toml index df28fcf..166ed19 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,6 +12,7 @@ CUSTOM_DOMAIN = "lolicon.in" [env.dev.vars] MODE = "debug" TARGET_UPSTREAM = "https://registry-1.docker.io" +CUSTOM_DOMAIN = "exmaple.com" [env.production] name = "cloudflare-docker-proxy"