File tree 7 files changed +15
-14
lines changed
7 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,7 @@ export class ApiHttpProvider extends HttpProvider {
43
43
44
44
public async handleRequest ( route : Route , request : http . IncomingMessage ) : Promise < HttpResponse > {
45
45
this . ensureAuthenticated ( request )
46
- // Only serve root pages.
47
- if ( route . requestPath && route . requestPath !== "/index.html" ) {
46
+ if ( ! this . isRoot ( route ) ) {
48
47
throw new HttpError ( "Not found" , HttpCode . NotFound )
49
48
}
50
49
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ export class DashboardHttpProvider extends HttpProvider {
20
20
}
21
21
22
22
public async handleRequest ( route : Route , request : http . IncomingMessage ) : Promise < HttpResponse > {
23
- // Only serve root pages.
24
- if ( route . requestPath && route . requestPath !== "/index.html" ) {
23
+ if ( ! this . isRoot ( route ) ) {
25
24
throw new HttpError ( "Not found" , HttpCode . NotFound )
26
25
}
27
26
Original file line number Diff line number Diff line change @@ -18,8 +18,7 @@ interface LoginPayload {
18
18
*/
19
19
export class LoginHttpProvider extends HttpProvider {
20
20
public async handleRequest ( route : Route , request : http . IncomingMessage ) : Promise < HttpResponse > {
21
- // Only serve root pages and only if password authentication is enabled.
22
- if ( this . options . auth !== AuthType . Password || ( route . requestPath && route . requestPath !== "/index.html" ) ) {
21
+ if ( this . options . auth !== AuthType . Password || ! this . isRoot ( route ) ) {
23
22
throw new HttpError ( "Not found" , HttpCode . NotFound )
24
23
}
25
24
switch ( route . base ) {
Original file line number Diff line number Diff line change @@ -41,10 +41,8 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
41
41
request : http . IncomingMessage ,
42
42
response : http . ServerResponse ,
43
43
) : Promise < HttpResponse > {
44
- const isRoot = ! route . requestPath || route . requestPath === "/index.html"
45
44
if ( ! this . authenticated ( request ) ) {
46
- // Only redirect from the root. Other requests get an unauthorized error.
47
- if ( isRoot ) {
45
+ if ( this . isRoot ( route ) ) {
48
46
return { redirect : "/login" , query : { to : route . fullPath } }
49
47
}
50
48
throw new HttpError ( "Unauthorized" , HttpCode . Unauthorized )
@@ -53,7 +51,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
53
51
// Ensure there is a trailing slash so relative paths work correctly.
54
52
const port = route . base . replace ( / ^ \/ / , "" )
55
53
const base = `${ this . options . base } /${ port } `
56
- if ( isRoot && ! route . fullPath . endsWith ( "/" ) ) {
54
+ if ( this . isRoot ( route ) && ! route . fullPath . endsWith ( "/" ) ) {
57
55
return {
58
56
redirect : `${ base } /` ,
59
57
}
Original file line number Diff line number Diff line change @@ -61,8 +61,7 @@ export class UpdateHttpProvider extends HttpProvider {
61
61
this . ensureAuthenticated ( request )
62
62
this . ensureMethod ( request )
63
63
64
- // Only serve root pages.
65
- if ( route . requestPath && route . requestPath !== "/index.html" ) {
64
+ if ( ! this . isRoot ( route ) ) {
66
65
throw new HttpError ( "Not found" , HttpCode . NotFound )
67
66
}
68
67
Original file line number Diff line number Diff line change @@ -128,8 +128,7 @@ export class VscodeHttpProvider extends HttpProvider {
128
128
129
129
switch ( route . base ) {
130
130
case "/" :
131
- // Only serve this at the root.
132
- if ( route . requestPath && route . requestPath !== "/index.html" ) {
131
+ if ( ! this . isRoot ( route ) ) {
133
132
throw new HttpError ( "Not found" , HttpCode . NotFound )
134
133
} else if ( ! this . authenticated ( request ) ) {
135
134
return { redirect : "/login" , query : { to : this . options . base } }
Original file line number Diff line number Diff line change @@ -359,6 +359,14 @@ export abstract class HttpProvider {
359
359
}
360
360
return cookies as T
361
361
}
362
+
363
+ /**
364
+ * Return true if the route is for the root page. For example /base, /base/,
365
+ * or /base/index.html but not /base/path or /base/file.js.
366
+ */
367
+ protected isRoot ( route : Route ) : boolean {
368
+ return ! route . requestPath || route . requestPath === "/index.html"
369
+ }
362
370
}
363
371
364
372
/**
You can’t perform that action at this time.
0 commit comments