mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 08:00:53 +00:00
warn once
This commit is contained in:
parent
ae07092705
commit
bba17d3141
@ -10,14 +10,17 @@ const isMiddlewareUsed = (app: express.Application, name: string) =>
|
||||
layer && layer.handle && layer.handle.name === name,
|
||||
).length;
|
||||
|
||||
const warnedMiddlewares = new Set<string>();
|
||||
|
||||
export const ensureRequiredMiddlewares = (app: express.Application) => {
|
||||
const requiredMiddlewares = ["cookieParser", "session"];
|
||||
|
||||
for (const name of requiredMiddlewares) {
|
||||
if (!isMiddlewareUsed(app, name)) {
|
||||
if (!isMiddlewareUsed(app, name) && !warnedMiddlewares.has(name)) {
|
||||
console.warn(
|
||||
`Required middleware '${name}' not found. Please ensure it is added to your express application.`,
|
||||
);
|
||||
warnedMiddlewares.add(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user