@@ -42,7 +42,7 @@ class ResourceMapper {
4242 }
4343
4444 // Maps the request for a given resource and representation format to a server file
45- // When searchIndex is true and the URL ends with a '/', indexFilename will be matched.
45+ // When searchIndex is true and the URL ends with a '/', and contentType includes 'text/html' indexFilename will be matched.
4646 async mapUrlToFile ( { url, contentType, createIfNotExists, searchIndex = true } ) {
4747 let fullPath = this . getFullPath ( url )
4848 let isIndex = searchIndex && fullPath . endsWith ( '/' )
@@ -53,7 +53,9 @@ class ResourceMapper {
5353 if ( createIfNotExists && contentType !== this . _indexContentType ) {
5454 throw new Error ( `Index file needs to have ${ this . _indexContentType } as content type` )
5555 }
56- fullPath += this . _indexFilename
56+ if ( contentType && contentType . includes ( this . _indexContentType ) ) {
57+ fullPath += this . _indexFilename
58+ }
5759 }
5860 // Create the path for a new file
5961 if ( createIfNotExists ) {
@@ -69,7 +71,7 @@ class ResourceMapper {
6971 const folder = fullPath . substr ( 0 , fullPath . length - filename . length )
7072
7173 // Find a file with the same name (minus the dollar extension)
72- let match = searchIndex ? await this . _getMatchingFile ( folder , filename , isIndex ) : ''
74+ let match = searchIndex ? await this . _getMatchingFile ( folder , filename , isIndex , contentType ) : ''
7375 if ( match === undefined ) {
7476 // Error if no match was found,
7577 // unless the URL ends with a '/',
@@ -87,13 +89,13 @@ class ResourceMapper {
8789 return { path, contentType : contentType || this . _defaultContentType }
8890 }
8991
90- async _getMatchingFile ( folder , filename , isIndex ) {
92+ async _getMatchingFile ( folder , filename , isIndex , contentType ) {
9193 const files = await this . _readdir ( folder )
9294 // Search for files with the same name (disregarding a dollar extension)
9395 if ( ! isIndex ) {
9496 return files . find ( f => this . _removeDollarExtension ( f ) === filename )
9597 // Check if the index file exists
96- } else if ( files . includes ( this . _indexFilename ) ) {
98+ } else if ( files . includes ( this . _indexFilename ) && contentType && contentType . includes ( this . _indexContentType ) ) {
9799 return this . _indexFilename
98100 }
99101 }
0 commit comments