From 71850e312bc981a62af80f96d64c4fef39706b62 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 10 Nov 2020 18:14:18 -0600 Subject: [PATCH] Avoid setting ?to=/ That's the default so it's extra visual noise. --- src/node/routes/domainProxy.ts | 2 +- src/node/routes/pathProxy.ts | 7 ++++--- src/node/routes/vscode.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/node/routes/domainProxy.ts b/src/node/routes/domainProxy.ts index ac249b80..fdffdc58 100644 --- a/src/node/routes/domainProxy.ts +++ b/src/node/routes/domainProxy.ts @@ -55,7 +55,7 @@ router.all("*", (req, res, next) => { } // Redirect all other pages to the login. return redirect(req, res, "login", { - to: req.path, + to: req.path !== "/" ? req.path : undefined, }) } diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index d21d08eb..15240219 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -1,6 +1,7 @@ import { Request, Router } from "express" import qs from "qs" import { HttpCode, HttpError } from "../../common/http" +import { normalize } from "../../common/util" import { authenticated, ensureAuthenticated, redirect } from "../http" import { proxy } from "../proxy" import { Router as WsRouter } from "../wsRouter" @@ -17,11 +18,11 @@ const getProxyTarget = (req: Request, rewrite: boolean): string => { router.all("/(:port)(/*)?", (req, res) => { if (!authenticated(req)) { - // If visiting the root (/proxy/:port and nothing else) redirect to the - // login page. + // If visiting the root (/:port only) redirect to the login page. if (!req.params[0] || req.params[0] === "/") { + const to = normalize(`${req.baseUrl}${req.path}`) return redirect(req, res, "login", { - to: `${req.baseUrl}${req.path}` || "/", + to: to !== "/" ? to : undefined, }) } throw new HttpError("Unauthorized", HttpCode.Unauthorized) diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index db2dc207..55200127 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -15,7 +15,8 @@ const vscode = new VscodeProvider() router.get("/", async (req, res) => { if (!authenticated(req)) { return redirect(req, res, "login", { - to: req.baseUrl, + // req.baseUrl can be blank if already at the root. + to: req.baseUrl && req.baseUrl !== "/" ? req.baseUrl : undefined, }) }