refactor: add helper fn getMaybeProxiedPathname

This commit is contained in:
Joe Previte
2022-12-21 15:13:59 -07:00
parent 19b7ba8735
commit fe33adc4bf
3 changed files with 48 additions and 14 deletions

View File

@@ -136,3 +136,17 @@ export async function getMaybeProxiedCodeServer(codeServer: CodeServerPage | Cod
return address
}
/**
* Stripes proxy base from url.pathname
* i.e. /<port>/ide + route returns just route
*/
export function getMaybeProxiedPathname(url: URL): string {
if (process.env.USE_PROXY === "1") {
// Behind proxy, path will be /<port>/ide + route
const pathWithoutProxy = url.pathname.split(`/${REVERSE_PROXY_BASE_PATH}`)[1]
return pathWithoutProxy
}
return url.pathname
}