File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,26 +109,29 @@ function getFilenameFromUrl(context, url) {
109109 throw new FilenameError ( "Forbidden" , 403 ) ;
110110 }
111111
112- // Strip the `pathname` property from the `publicPath` option from the start of requested url
113- // `/complex/foo.js` => `foo.js`
114- // and add outputPath
115- // `foo.js` => `/home/user/my-project/dist/foo.js`
112+ let index ;
113+
114+ if ( pathname && pathname . endsWith ( "/" ) ) {
115+ if ( options . index === false ) {
116+ return ;
117+ }
118+ index =
119+ typeof options . index === "string" ? options . index : "index.html" ;
120+ }
121+
122+ // Builds the absolute path of the file to serve:
123+ // - If the URL ends with '/', appends the index file (index.html or custom) to the directory path.
124+ // - If the URL does not end with '/', only joins the relative path to outputPath.
125+ // Example:
126+ // URL: /complex/foo.js => outputPath/complex/foo.js
127+ // URL: /complex/ => outputPath/complex/index.html (or the configured index file)
116128 filename = path . join (
117129 outputPath ,
118130 pathname . slice ( publicPathPathname . length ) ,
131+ index || "" ,
119132 ) ;
120133
121134 try {
122- if ( pathname [ pathname . length - 1 ] === "/" ) {
123- if ( options . index === false ) {
124- return ;
125- } else if ( typeof options . index === "string" ) {
126- filename = path . join ( filename , options . index ) ;
127- } else {
128- filename = path . join ( filename , "index.html" ) ;
129- }
130- }
131-
132135 extra . stats = context . outputFileSystem . statSync ( filename ) ;
133136 } catch {
134137 continue ;
You can’t perform that action at this time.
0 commit comments