From 2a3cc30cca38b7fc8f8717fabbe75021e3a9d087 Mon Sep 17 00:00:00 2001 From: Dan Habot Date: Fri, 23 Oct 2020 00:17:12 -0400 Subject: [PATCH] Added logging --- bin/serve.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/bin/serve.js b/bin/serve.js index 9a09129f..ed6ffe1c 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -70,32 +70,34 @@ const getHelp = () => chalk` {bold OPTIONS} - --help Shows this help message + --help Shows this help message - -v, --version Displays the current version of serve + -v, --version Displays the current version of serve - -l, --listen {underline listen_uri} Specify a URI endpoint on which to listen (see below) - - more than one may be specified to listen in multiple places + -l, --listen {underline listen_uri} Specify a URI endpoint on which to listen (see below) - + more than one may be specified to listen in multiple places - -d, --debug Show debugging information + -d, --debug Show debugging information - -s, --single Rewrite all not-found requests to \`index.html\` + -s, --single Rewrite all not-found requests to \`index.html\` - -c, --config Specify custom path to \`serve.json\` + -c, --config Specify custom path to \`serve.json\` - -C, --cors Enable CORS, sets \`Access-Control-Allow-Origin\` to \`*\` + -C, --cors Enable CORS, sets \`Access-Control-Allow-Origin\` to \`*\` - -n, --no-clipboard Do not copy the local address to the clipboard + -n, --no-clipboard Do not copy the local address to the clipboard - -u, --no-compression Do not compress files + -u, --no-compression Do not compress files - --no-etag Send \`Last-Modified\` header instead of \`ETag\` + --no-etag Send \`Last-Modified\` header instead of \`ETag\` - -S, --symlinks Resolve symlinks instead of showing 404 errors + -S, --symlinks Resolve symlinks instead of showing 404 errors - --ssl-cert Optional path to an SSL/TLS certificate to serve with HTTPS + --ssl-cert Optional path to an SSL/TLS certificate to serve with HTTPS - --ssl-key Optional path to the SSL/TLS certificate\'s private key + --ssl-key Optional path to the SSL/TLS certificate\'s private key + + --log Output a log of requests {bold ENDPOINTS} @@ -193,6 +195,10 @@ const startEndpoint = (endpoint, config, args, previous) => { await compressionHandler(request, response); } + if (args['--log']) { + console.log(`${chalk.cyan((new Date()).toString())} Sending ${chalk.yellow(request.url)} to ${chalk.green(request.connection.remoteAddress)}`); + } + return handler(request, response, config); }; @@ -384,6 +390,7 @@ const loadConfig = async (cwd, entry, args) => { '-u': '--no-compression', '-S': '--symlinks', '-C': '--cors', + '--log': Boolean, // This is deprecated and only for backwards-compatibility. '-p': '--listen' });