Skip to content

Commit

Permalink
Merge branch 'resourceMapper' of https://github.com/solid/node-solid-…
Browse files Browse the repository at this point in the history
…server into main
  • Loading branch information
bourgeoa committed Nov 5, 2024
2 parents a8bf8c4 + b00726f commit 417bf13
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 97 deletions.
2 changes: 1 addition & 1 deletion lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class LDP {
({ path, contentType } = await this.resourceMapper.mapUrlToFile({ url: options, searchIndex }))
stats = await this.stat(path)
} catch (err) {
throw error(404, 'Can\'t find file requested: ' + options)
throw error(err.status || 500, err.message)
}

// Just return, since resource exists
Expand Down
6 changes: 4 additions & 2 deletions lib/resource-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ResourceMapper {

// Find a file with the same name (minus the dollar extension)
let match = ''
if (match === '') { // always true to keep indentation
try {
const files = await this._readdir(folder)
// Search for files with the same name (disregarding a dollar extension)
if (!isFolder) {
Expand All @@ -134,13 +134,15 @@ class ResourceMapper {
} else if (searchIndex && files.includes(this._indexFilename)) {
match = this._indexFilename
}
} catch (err) {
throw new HTTPError(404, `${filePath} Resource not found`)
}
// Error if no match was found (unless URL ends with '/', then fall back to the folder)
if (match === undefined) {
if (isIndex) {
match = ''
} else {
throw new HTTPError(404, `Resource not found: ${pathname}`)
throw new HTTPError(404, `${pathname} Resource not found`)
}
}
path = `${folder}${match}`
Expand Down
Loading

0 comments on commit 417bf13

Please sign in to comment.