Skip to content

Commit

Permalink
Do not error, if no content-type could be found for a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ida committed May 8, 2023
1 parent 2a66467 commit 6483bb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

## 1.2.5 (unreleased)

* Do not error, if no content-type could be found for a file.

* Add empty favicon for error-template and display
error-stack (traceback).


## 1.2.4 (2022-06-19)

* Do not redirect after posting a form, takes ages in lynx.
Expand Down
12 changes: 7 additions & 5 deletions lib/find_answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ function sendStaticFile(filePath, res) {
res.end('Could not read file "' + filePath + '" ', err)
} else {
const extension = path.extname(filePath).slice(1)
const type = extension ? contentTypes[extension] : null
if( ! type ) {
const type = contentTypes[extension]
if(type === undefined) {
res.writeHead(404, { 'Content-Type': 'text/html' })
res.end('Content-type "' + type + '"not found')
res.end('Content-type for "' + filePath + '" not found')
}
else {
res.writeHead(200, { 'Content-Type': type })
res.end(data)
}
res.writeHead(200, { 'Content-Type': type })
res.end(data)
}
});
}
Expand Down

0 comments on commit 6483bb2

Please sign in to comment.