Skip to content

Commit

Permalink
Remove query options from the webserver's directory listing
Browse files Browse the repository at this point in the history
The `?all` option would show the full directory listing instead of one
that is reduced to only PDF files and folders. However, in practice I
find that the reduced listing is never really useful because non-PDF
files such as `web/viewer.html` are accessed much more often, and thus
opening the full view is usually the first action I perform.

The `?frame` option puts the directory listing in a resizable frame, but
the other side of the frame is always empty. This functionality is traced
back to the original code from commit 4df24f4 from 2014, but even back
then I doubt this was ever really used.

The `?side` option would show the reduced directory listing without the
link to go to the full view.

Overall, none of the options seem useful nowadays, so we remove all of
them to simplify the code (in preparation of upcoming refactoring of
this file) and to make the directory listing more useful by default.

Finally, now that we always show the full directory listing we change
the header to "Index of <path>" because it shows more than just PDFs and
it matches implementations of other webservers such as Nginx and Apache.
  • Loading branch information
timvandermeij committed Feb 11, 2024
1 parent 4b7382e commit 7e2ff41
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions test/webserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ WebServer.prototype = {
res.end("Bad request", "utf8");
return;
}
var queryPart = urlParts[3];
var verbose = this.verbose;

var methodHooks = this.hooks[req.method];
Expand Down Expand Up @@ -206,25 +205,14 @@ WebServer.prototype = {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);

if (queryPart === "frame") {
res.end(
"<html><frameset cols=*,200><frame name=pdf>" +
'<frame src="' +
encodeURI(pathPart) +
'?side"></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 +240,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 +260,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 7e2ff41

Please sign in to comment.