@@ -3,7 +3,7 @@ import { Server } from "http"
33import path from "path"
44import { AuthType , DefaultedArgs } from "../cli"
55import { version as codeServerVersion , vsRootPath } from "../constants"
6- import { ensureAuthenticated } from "../http"
6+ import { ensureAuthenticated , authenticated , redirect } from "../http"
77import { loadAMDModule } from "../util"
88import { Router as WsRouter , WebsocketRouter } from "../wsRouter"
99import { 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