Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,28 @@ module.exports = function createMiddleware(_dir, _options) {
})
}

function statWithAccess (file, cb) {
fs.stat(file, (err, stat) => {
if (err) {
cb(err);
return;
}
fs.access(file, fs.constants.R_OK, (err) => {
stat.readable = !err;
cb(err, stat);
});
});
}


function statFile() {
try {
fs.stat(file, (err, stat) => {
if (err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) {
statWithAccess(file, (err, stat) => {
const effectively404 =
(err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) ||
(!stat || !stat.readable);

if (effectively404) {
if (req.statusCode === 404) {
// This means we're already trying ./404.html and can not find it.
// So send plain text response with 404 status code
Expand Down