From ab00b34a96ceda8147e8c5878cdb9205df372222 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 4 Jan 2023 14:02:53 +0000 Subject: [PATCH] fix(indiekit): enable debugging when debug flag set --- packages/indiekit/bin/cli.js | 6 ++++-- packages/indiekit/lib/middleware/logging.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/indiekit/bin/cli.js b/packages/indiekit/bin/cli.js index 93f382994..56fe89bf3 100755 --- a/packages/indiekit/bin/cli.js +++ b/packages/indiekit/bin/cli.js @@ -1,6 +1,7 @@ #!/usr/bin/env node -import process from "node:process"; import { Command } from "commander"; +import makeDebug from "debug"; + import { Indiekit } from "@indiekit/indiekit"; import { defaultConfig } from "../config/defaults.js"; @@ -19,7 +20,8 @@ program const { debug, port } = options; if (debug) { - process.env.DEBUG = debug ? `${debug}:*` : "*"; + // Debug everything if no scope, else only debug within provided scope + makeDebug.enable(debug === true ? `*` : debug); } const indiekit = new Indiekit({ diff --git a/packages/indiekit/lib/middleware/logging.js b/packages/indiekit/lib/middleware/logging.js index ce260da32..198eb028f 100644 --- a/packages/indiekit/lib/middleware/logging.js +++ b/packages/indiekit/lib/middleware/logging.js @@ -1,8 +1,11 @@ -import Debug from "debug"; +import makeDebug from "debug"; -const debug = new Debug("indiekit:request"); +const debug = makeDebug("indiekit:request"); export const logging = (request, response, next) => { + // Send debug logging output to console.info + debug.log = console.info.bind(console); + debug("url", request.originalUrl); debug("headers", request.headers); debug("body", request.body);