chore: add debug logs to middleware
This commit is contained in:
parent
27ecf0f9b2
commit
b48fe51f46
@ -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();
|
||||
}
|
@ -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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user