@@ -3554,10 +3554,12 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
3554
3554
pathStrings := strings .Split (r .URL .Path , "/" )
3555
3555
3556
3556
// numPieces will be 2 if the request was for the root directory (https://server/), or if
3557
- // the request included only a single path component (https://server/someuser/)
3557
+ // the request included only a single path component (https://server/someuser) and no trailing slash
3558
+ var dbName , userName string
3558
3559
numPieces := len (pathStrings )
3559
- if numPieces == 2 {
3560
- userName := pathStrings [1 ]
3560
+ switch numPieces {
3561
+ case 2 :
3562
+ userName = pathStrings [1 ]
3561
3563
// Check if the request was for the root directory
3562
3564
if pathStrings [1 ] == "" {
3563
3565
// Yep, root directory request
@@ -3568,10 +3570,31 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
3568
3570
// The request was for a user page
3569
3571
userPage (w , r , userName )
3570
3572
return
3573
+ case 3 :
3574
+ userName = pathStrings [1 ]
3575
+ dbName = pathStrings [2 ]
3576
+
3577
+ // This catches the case where a "/" is on the end of a user page URL
3578
+ if dbName == "" {
3579
+ // The request was for a user page
3580
+ userPage (w , r , userName )
3581
+ return
3582
+ }
3583
+ default :
3584
+ // TODO: Add support for folders and sub folders
3585
+ // TODO eg: Allow for collections of databases
3586
+ // TODO * /user/collectionFoo/database1
3587
+ // TODO * /user/collectionFoo/database2
3588
+ // TODO * /user/collectionBar/database1
3589
+ // TODO * /user/collectionBar/database2
3590
+
3591
+ // We haven't yet added support for folders and subfolders, so bounce back to the /user/database page
3592
+ http .Redirect (w , r , fmt .Sprintf ("/%s/%s" , pathStrings [1 ], pathStrings [2 ]), http .StatusTemporaryRedirect )
3593
+ return
3571
3594
}
3572
3595
3573
- userName : = pathStrings [1 ]
3574
- dbName : = pathStrings [2 ]
3596
+ userName = pathStrings [1 ]
3597
+ dbName = pathStrings [2 ]
3575
3598
3576
3599
// Validate the user supplied user and database name
3577
3600
err := com .ValidateUserDB (userName , dbName )
@@ -3580,14 +3603,6 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
3580
3603
return
3581
3604
}
3582
3605
3583
- // This catches the case where a "/" is on the end of a user page URL
3584
- // TODO: Refactor this and the above identical code. Doing it this way is non-optimal
3585
- if pathStrings [2 ] == "" {
3586
- // The request was for a user page
3587
- userPage (w , r , userName )
3588
- return
3589
- }
3590
-
3591
3606
// TODO: Add support for folders and sub-folders in request paths
3592
3607
dbFolder := "/"
3593
3608
0 commit comments