Skip to content

Commit

Permalink
rebuilt
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Nov 26, 2022
1 parent f58a074 commit a59aff9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bin/srvd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const DEFAULT_PORT = 8080;
const TRUES = ["TRUE", "True", "true", true];

function serve(
{ acceptRanges = true, debug = false, log = console.log, max = Infinity, wait = 60, root, port } = {
{ acceptRanges = true, debug = false, infer = true, log = console.log, max = Infinity, wait = 60, root, port } = {
acceptRanges: true,
infer: true,
max: Infinity,
wait: 60
}
Expand Down Expand Up @@ -79,7 +80,7 @@ function serve(
if (debug) log(`[srvd] received a "${req.method}" request for "${req.url}"`);

let filepath = path.join(root, req.url);
if (!fs.existsSync(filepath) && fs.existsSync(filepath + ".html")) {
if (infer && !fs.existsSync(filepath) && fs.existsSync(filepath + ".html")) {
if (debug) console.log(`[srvd] inferred ${req.url}.html`);
req.url += ".html";
}
Expand Down Expand Up @@ -107,7 +108,7 @@ function serve(
clearTimeouts();
});

return { acceptRanges, debug, log, max, server, port, root, wait };
return { acceptRanges, debug, infer, log, max, server, port, root, wait };
}

const srvd = { serve };
Expand All @@ -126,6 +127,7 @@ if (require.main === module) {

serve({
debug: !!str.match(/-?-debug((=|== )(true|True|TRUE))?/),
infer: !!str.match(/-?-infer((=|== )(true|True|TRUE))?/),
max: Array.prototype.slice.call(str.match(/-?-max(?:=|== )(\d+)/) || [], 1)[0],
port: Array.prototype.slice.call(str.match(/-?-port(?:=|== )(\d+)/) || [], 1)[0],
root: Array.prototype.slice.call(str.match(/-?-root(?:=|== )([^ ]+)/) || [], 1)[0],
Expand Down

0 comments on commit a59aff9

Please sign in to comment.