1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-26 12:15:26 +00:00

Avoid setting ?to=/

That's the default so it's extra visual noise.
This commit is contained in:
Asher 2020-11-10 18:14:18 -06:00
parent b8340a2ae9
commit 71850e312b
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
3 changed files with 7 additions and 5 deletions

View File

@ -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,
})
}

View File

@ -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)

View File

@ -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,
})
}