File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,7 +52,10 @@ export function handleApplication(scope: Scope) {
5252 staticFiles . set ( entry . urlPath , entry . absolutePath ) ;
5353 // If the file is an index.html, also store it in the index entries
5454 if ( entry . urlPath . endsWith ( 'index.html' ) ) {
55- indexEntries . set ( dirname ( entry . urlPath ) , entry . absolutePath ) ;
55+ // Without trailing slash; null -> 301 redirect to trailing slash
56+ indexEntries . set ( dirname ( entry . urlPath ) , null ) ;
57+ // With trailing slash; serves the index.html file
58+ indexEntries . set ( join ( dirname ( entry . urlPath ) , '/' ) , entry . absolutePath ) ;
5659 }
5760 break ;
5861 case 'unlink' :
@@ -90,7 +93,18 @@ export function handleApplication(scope: Scope) {
9093 }
9194
9295 if ( index ) {
96+ // Retrieve index entry
9397 staticFile = indexEntries . get ( req . pathname ) ;
98+
99+ // If `null`, redirect to trailing slash
100+ if ( staticFile === null ) {
101+ return {
102+ status : 301 ,
103+ headers : {
104+ Location : join ( req . pathname , '/' ) ,
105+ } ,
106+ }
107+ }
94108 }
95109 }
96110
You can’t perform that action at this time.
0 commit comments