Skip to content

Commit 4805186

Browse files
committed
revert(vscode): add missing route with redirect
1 parent 35381c0 commit 4805186

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/node/routes/vscode.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Server } from "http"
33
import path from "path"
44
import { AuthType, DefaultedArgs } from "../cli"
55
import { version as codeServerVersion, vsRootPath } from "../constants"
6-
import { ensureAuthenticated } from "../http"
6+
import { ensureAuthenticated, authenticated, redirect } from "../http"
77
import { loadAMDModule } from "../util"
88
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
99
import { errorHandler } from "./errors"
@@ -53,6 +53,17 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
5353
const router = express.Router()
5454
const wsRouter = WsRouter()
5555

56+
router.get("/", async (req, res, next) => {
57+
const isAuthenticated = await authenticated(req)
58+
if (!isAuthenticated) {
59+
return redirect(req, res, "login", {
60+
// req.baseUrl can be blank if already at the root.
61+
to: req.baseUrl && req.baseUrl !== "/" ? req.baseUrl : undefined,
62+
})
63+
}
64+
next()
65+
})
66+
5667
router.all("*", ensureAuthenticated, (req, res, next) => {
5768
req.on("error", (error) => errorHandler(error, req, res, next))
5869

0 commit comments

Comments
 (0)