chore: add debug logs to middleware
Some checks failed
Build & Push Docker Image / build (push) Successful in 24s
Test & Build / build (push) Has been cancelled

This commit is contained in:
Corban-Lee Jones 2025-05-27 12:16:19 +01:00
parent 27ecf0f9b2
commit b48fe51f46
2 changed files with 13 additions and 1 deletions

View File

@ -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();
}

View File

@ -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/<id>/<page>'
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();
}