1
This commit is contained in:
Evan Pratten 2023-03-30 09:12:30 -04:00
parent 44b914d8bb
commit 4d29bfebc5

View File

@ -18,19 +18,19 @@ export function onRequest(context) {
url.port = ""; url.port = "";
// If the path is just /v2 then redirect upstream // If the path is just /v2 then redirect upstream
if (url.pathname == "/v2" || url.pathname == "/v2/") { // if (url.pathname == "/v2" || url.pathname == "/v2/") {
return Response.redirect(TARGET_URL.toString(), 302); // return Response.redirect(TARGET_URL.toString(), 302);
} // }
// If the path starts with an allowed user, redirect to the new url // // If the path starts with an allowed user, redirect to the new url
for (var user of ALLOWED_EXTRA_USERS) { // for (var user of ALLOWED_EXTRA_USERS) {
if (url.pathname.startsWith(`/v2/${user}/`)) { // if (url.pathname.startsWith(`/v2/${user}/`)) {
return Response.redirect(url.toString(), 302); // return Response.redirect(url.toString(), 302);
} // }
} // }
// Inject the default user into the path after /v2/ // // Inject the default user into the path after /v2/
url.pathname = url.pathname.replace("/v2/", `/v2/${DEFAULT_USER}/`); // url.pathname = url.pathname.replace("/v2/", `/v2/${DEFAULT_USER}/`);
// Redirect to the new url // Redirect to the new url
return Response.redirect(url.toString(), 302); return Response.redirect(url.toString(), 302);