« get me outta code hell

write: live-dev-server: --quiet-responses to hide 200/404 - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-07-30 18:43:57 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-30 18:43:57 -0300
commit75dc9853c03f764589f99bfd181f14b573c975dc (patch)
treee3515f574d409feabb6e5773e1d4dac7836c6c7d /src
parent093d425a02ff144a0f5c6475eadc537d7fd1f041 (diff)
write: live-dev-server: --quiet-responses to hide 200/404
Diffstat (limited to 'src')
-rw-r--r--src/write/build-modes/live-dev-server.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index d7c33d87..78c3928f 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -56,6 +56,11 @@ export function getCLIOptions() {
         return true;
       },
     },
+
+    'quiet-responses': {
+      help: `Disables outputting [200] and [404] responses in the server log`,
+      type: 'flag',
+    },
   };
 }
 
@@ -86,6 +91,7 @@ export async function go({
 
   const host = cliOptions['host'] ?? defaultHost;
   const port = parseInt(cliOptions['port'] ?? defaultPort);
+  const quietResponses = cliOptions['quiet-responses'] ?? false;
 
   const contentDependenciesWatcher = await watchContentDependencies();
   const {contentDependencies: allContentDependencies} = contentDependenciesWatcher;
@@ -167,7 +173,7 @@ export async function go({
         });
         response.writeHead(200, contentTypeJSON);
         response.end(json);
-        console.log(`${requestHead} [200] /data.json`);
+        if (!quietResponses) console.log(`${requestHead} [200] /data.json`);
       } catch (error) {
         response.writeHead(500, contentTypeJSON);
         response.end({error: `Internal error serializing wiki JSON`});
@@ -263,7 +269,7 @@ export async function go({
         await pipeline(
           createReadStream(filePath),
           response);
-        console.log(`${requestHead} [200] ${pathname}`);
+        if (!quietResponses) console.log(`${requestHead} [200] ${pathname}`);
       } catch (error) {
         response.writeHead(500, contentTypePlain);
         response.end(`Failed during file-to-response pipeline`);
@@ -281,7 +287,7 @@ export async function go({
     if (!Object.hasOwn(urlToPageMap, pathnameKey)) {
       response.writeHead(404, contentTypePlain);
       response.end(`No page found for: ${pathnameKey}\n`);
-      console.log(`${requestHead} [404] ${pathname}`);
+      if (!quietResponses) console.log(`${requestHead} [404] ${pathname}`);
       return;
     }
 
@@ -462,7 +468,7 @@ export async function go({
 
       const pageHTML = topLevelResult.toString();
 
-      console.log(`${requestHead} [200] ${pathname}`);
+      if (!quietResponses) console.log(`${requestHead} [200] ${pathname}`);
       response.writeHead(200, contentTypeHTML);
       response.end(pageHTML);
     } catch (error) {
@@ -492,6 +498,9 @@ export async function go({
   server.on('listening', () => {
     logInfo`${'All done!'} Listening at: ${address}`;
     logInfo`Press ^C here (control+C) to stop the server and exit.`;
+    if (quietResponses) {
+      logInfo`Suppressing [200] and [404] response logging.`;
+    }
   });
 
   server.listen(port, host);