mirror of
https://github.com/ciiiii/cloudflare-docker-proxy.git
synced 2025-12-06 14:42:51 +08:00
Compare commits
1 Commits
yscai/fix-
...
yscai/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
143b47184a |
25
.github/workflows/stage.yaml
vendored
Normal file
25
.github/workflows/stage.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
3023
package-lock.json
generated
3023
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@
|
||||
"scripts": {
|
||||
"format": "prettier --write '**/*.{js,css,json,md}'",
|
||||
"build": "webpack",
|
||||
"dev": "npx wrangler dev src/index.js --env dev"
|
||||
"dev": "wrangler dev src/index.js --env dev"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "src/index.js"
|
||||
|
||||
17
src/index.js
17
src/index.js
@@ -32,9 +32,6 @@ 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(
|
||||
@@ -108,22 +105,12 @@ async function handleRequest(request) {
|
||||
const newReq = new Request(newUrl, {
|
||||
method: request.method,
|
||||
headers: request.headers,
|
||||
// don't follow redirect to dockerhub blob upstream
|
||||
redirect: isDockerHub ? "manual" : "follow",
|
||||
redirect: "manual",
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -157,7 +144,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",
|
||||
|
||||
Reference in New Issue
Block a user