diff options
Diffstat (limited to 'src/write/build-modes')
-rw-r--r-- | src/write/build-modes/live-dev-server.js | 17 |
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); |