Create helper for determining if route is the root

This commit is contained in:
Asher
2020-04-01 11:28:09 -05:00
parent 74a0bacdcf
commit 411c61fb02
7 changed files with 15 additions and 14 deletions

View File

@@ -41,10 +41,8 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
request: http.IncomingMessage,
response: http.ServerResponse,
): Promise<HttpResponse> {
const isRoot = !route.requestPath || route.requestPath === "/index.html"
if (!this.authenticated(request)) {
// Only redirect from the root. Other requests get an unauthorized error.
if (isRoot) {
if (this.isRoot(route)) {
return { redirect: "/login", query: { to: route.fullPath } }
}
throw new HttpError("Unauthorized", HttpCode.Unauthorized)
@@ -53,7 +51,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
// Ensure there is a trailing slash so relative paths work correctly.
const port = route.base.replace(/^\//, "")
const base = `${this.options.base}/${port}`
if (isRoot && !route.fullPath.endsWith("/")) {
if (this.isRoot(route) && !route.fullPath.endsWith("/")) {
return {
redirect: `${base}/`,
}