mirror of
https://github.com/ciiiii/cloudflare-docker-proxy.git
synced 2026-04-03 11:55:06 +08:00
improve use of worker variables
This commit is contained in:
19
src/index.js
19
src/index.js
@@ -14,26 +14,31 @@ function routeByHosts(host) {
|
||||
if (host in routes) {
|
||||
return routes[host];
|
||||
}
|
||||
return TARGET_UPSTREAM ? TARGET_UPSTREAM : "";
|
||||
if (MODE == "debug") {
|
||||
return TARGET_UPSTREAM;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
async function handleRequest(request) {
|
||||
const url = new URL(request.url);
|
||||
if (url.pathname == "/v2/") {
|
||||
const resp = new Response({}, { status: 401 });
|
||||
resp.headers = new Headers();
|
||||
if (DEBUG) {
|
||||
resp.headers.set(
|
||||
const headers = new Headers();
|
||||
if (MODE == "debug") {
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="${LOCAL_ADDRESS}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
} else {
|
||||
resp.headers.set(
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="https://${url.hostname}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
}
|
||||
return resp;
|
||||
return new Response(JSON.stringify({ message: "UNAUTHORIZED" }), {
|
||||
status: 401,
|
||||
headers: headers,
|
||||
});
|
||||
}
|
||||
const upstream = routeByHosts(url.hostname);
|
||||
if (upstream === "") {
|
||||
|
||||
Reference in New Issue
Block a user