From b48fe51f46bb2bd79058563e2fe7e65e1c476a0f Mon Sep 17 00:00:00 2001 From: Corban-Lee Date: Tue, 27 May 2025 12:16:19 +0100 Subject: [PATCH] chore: add debug logs to middleware --- src/server/middleware/attachGuilds.ts | 5 +++++ src/server/middleware/guildTabHelper.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/server/middleware/attachGuilds.ts b/src/server/middleware/attachGuilds.ts index b019e4c..1f3f1d6 100644 --- a/src/server/middleware/attachGuilds.ts +++ b/src/server/middleware/attachGuilds.ts @@ -1,10 +1,15 @@ import { Request, Response, NextFunction } from "express"; import { client as bot } from "@bot/bot"; +import { getLogger } from "@server/../log"; +const logger = getLogger(__filename); + +// Todo: update this comment as a jsdoc // The purpose of this middleware is to attach an object containing cached // Discord servers to the response, which is accessible in the DOM. // This is primarily used for rendering servers on the sidebar. export const attachGuilds = (_request: Request, response: Response, next: NextFunction) => { + logger.debug(`Attaching ${bot.guilds.cache.size} cached guilds to the response locals`); response.locals.guilds = bot.guilds.cache.map(guild => guild); next(); } \ No newline at end of file diff --git a/src/server/middleware/guildTabHelper.ts b/src/server/middleware/guildTabHelper.ts index 853aac0..98712c8 100644 --- a/src/server/middleware/guildTabHelper.ts +++ b/src/server/middleware/guildTabHelper.ts @@ -1,10 +1,17 @@ import { Request, Response, NextFunction } from "express"; +import { getLogger } from "@server/../log"; + +const logger = getLogger(__filename); // This middleware returns the last segment of the url path. // It's used to identify which tab to highlight as active on // the guild view at '/guild//' export const guildTabHelper = (request: Request, response: Response, next: NextFunction) => { const currentPath = request.path.split("/") - response.locals.guildPage = currentPath[currentPath.length - 1] + const guildPage = currentPath[currentPath.length - 1]; + + logger.debug(`Attaching '${guildPage}' tab helper to response locals`); + + response.locals.guildPage = guildPage; next(); } \ No newline at end of file