6 Commits

Author SHA1 Message Date
ciiiii
5f0b9200de Update format 2025-11-15 21:32:44 -07:00
ciiiii
c7ca5c64f9 Update README 2025-11-15 21:31:20 -07:00
Yisheng Cai
c595a14166 Redirect for index route (#121)
Some checks failed
Deploy to Cloudflare Workers / Build & Deploy (push) Has been cancelled
2025-06-01 16:13:44 +08:00
ciiiii
dfac79db55 Handle dockerhub blob redirect
Some checks failed
Deploy to Cloudflare Workers / Build & Deploy (push) Has been cancelled
2025-02-16 18:14:20 -06:00
ciiiii
e176bc4b29 Remove stage deployment 2025-02-16 12:35:01 -06:00
Yisheng Cai
47001590eb Change redirect mode from follow to manual (#104) 2025-02-17 02:30:59 +08:00
7 changed files with 3562 additions and 528 deletions

View File

@@ -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

View File

@@ -1,5 +1,14 @@
# cloudflare-docker-proxy
> ### ⚠️ **Important Notice**
> <span style="color:#d73a49;font-weight:bold">Docker Hub is rate-limiting Cloudflare Worker IPs, causing frequent <code>429</code> errors.</span>
> <span style="color:#d73a49;font-weight:bold">This project is currently NOT recommended for production use.</span>
Due to the current instability, this project is not recommended for production use.
We will provide updates as soon as more information becomes available.
![deploy](https://github.com/ciiiii/cloudflare-docker-proxy/actions/workflows/deploy.yaml/badge.svg)
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/ciiiii/cloudflare-docker-proxy)

3023
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@
"scripts": {
"format": "prettier --write '**/*.{js,css,json,md}'",
"build": "webpack",
"dev": "wrangler dev src/index.js --env dev"
"dev": "npx wrangler dev src/index.js --env dev"
},
"license": "MIT",
"main": "src/index.js"

View File

@@ -32,6 +32,9 @@ function routeByHosts(host) {
async function handleRequest(request) {
const url = new URL(request.url);
if (url.pathname == "/") {
return Response.redirect(url.protocol + "//" + url.host + "/v2/", 301);
}
const upstream = routeByHosts(url.hostname);
if (upstream === "") {
return new Response(
@@ -105,12 +108,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;
}
@@ -144,7 +157,7 @@ async function fetchToken(wwwAuthenticate, scope, authorization) {
}
function responseUnauthorized(url) {
const headers = new(Headers);
const headers = new Headers();
if (MODE == "debug") {
headers.set(
"Www-Authenticate",

View File

@@ -12,6 +12,7 @@ CUSTOM_DOMAIN = "libcuda.so"
[env.dev.vars]
MODE = "debug"
TARGET_UPSTREAM = "https://registry-1.docker.io"
CUSTOM_DOMAIN = "exmaple.com"
[env.production]
name = "cloudflare-docker-proxy"

1013
yarn.lock

File diff suppressed because it is too large Load Diff