@@ -3,7 +3,7 @@ import { Server } from "http"
3
3
import path from "path"
4
4
import { AuthType , DefaultedArgs } from "../cli"
5
5
import { version as codeServerVersion , vsRootPath } from "../constants"
6
- import { ensureAuthenticated } from "../http"
6
+ import { ensureAuthenticated , authenticated , redirect } from "../http"
7
7
import { loadAMDModule } from "../util"
8
8
import { Router as WsRouter , WebsocketRouter } from "../wsRouter"
9
9
import { errorHandler } from "./errors"
@@ -53,6 +53,17 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
53
53
const router = express . Router ( )
54
54
const wsRouter = WsRouter ( )
55
55
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
+
56
67
router . all ( "*" , ensureAuthenticated , ( req , res , next ) => {
57
68
req . on ( "error" , ( error ) => errorHandler ( error , req , res , next ) )
58
69
0 commit comments