Skip to content

Commit

Permalink
Only show the full webserver's directory listing
Browse files Browse the repository at this point in the history
The webserver by default shows a directory listing that is reduced to
only PDF files and folders. However, in practice this is rarely useful
because other files (like `web/viewer.html`) are accessed more often and
that now always requires an extra click. Moreover, it doesn't match
directory listing behavior of known webservers like Nginx or Apache.
This commit thefore aligns the behavior and header with other webserver
implementations to provide better defaults and simplify the code.
  • Loading branch information
timvandermeij committed Feb 11, 2024
1 parent 440208d commit 42423b1
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions test/webserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,19 @@ WebServer.prototype = {
"<html><frameset cols=*,200><frame name=pdf>" +
'<frame src="' +
encodeURI(pathPart) +
'?side"></frameset></html>',
'"></frameset></html>',
"utf8"
);
return;
}
var all = queryPart === "all";
fs.readdir(dir, function (err, files) {
if (err) {
res.end();
return;
}
res.write(
'<html><head><meta charset="utf-8"></head><body>' +
"<h1>PDFs of " +
"<h1>Index of " +
pathPart +
"</h1>\n"
);
Expand Down Expand Up @@ -252,7 +251,7 @@ WebServer.prototype = {
href = "/web/viewer.html?file=" + encodeURIComponent(item);
label = file;
extraAttributes = ' target="pdf"';
} else if (all) {
} else {
href = encodeURI(item);
label = file;
}
Expand All @@ -272,12 +271,6 @@ WebServer.prototype = {
if (files.length === 0) {
res.write("<p>no files found</p>\n");
}
if (!all && queryPart !== "side") {
res.write(
"<hr><p>(only PDF files are shown, " +
'<a href="?all">show all</a>)</p>\n'
);
}
res.end("</body></html>");
});
}
Expand Down

0 comments on commit 42423b1

Please sign in to comment.