Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function maybeServeIndexFile() {
const indexPath = Path.join(path, directoryIndex);
fs.stat(indexPath, function(err, stats) {
if(err) {
if(err.code === 'ENOENT' && !disableIndexes) {
// Fallback to a directory listing instead
serveDirListing();
} else {
// Let the error (likely 404) pass through instead
serveError(path, err);
}
} else {
// Index file found, serve that instead
serveFile(indexPath, stats);
}
});
}