@samitouri / QOSami-HFS / commits / 66415f1a

dx: log plugins changing response

Massimo Melina committed Jan 6, 2024 at 15:50 UTC 66415f1ac04e011958cfb8d573defa2240ee25d8
1 file changed +7
src/plugins.ts
+7
@@ -111,9 +111,16 @@ async function initPlugin<T>(pl: any, more?: T) {
111 export const pluginsMiddleware: Koa.Middleware = async (ctx, next) => {
112 const after: Dict<CallMeAfter> = {}
113 // run middleware plugins
114 + let lastStatus = ctx.status
115 + let lastBody = ctx.body
116 await Promise.all(mapPlugins(async (pl, id) => {
117 try {
118 const res = await pl.middleware?.(ctx)
119 + if (lastStatus !== ctx.status || lastBody !== ctx.body) {
120 + console.debug("plugin changed response", id)
121 + lastStatus = ctx.status
122 + lastBody = ctx.body
123 + }
124 if (res === true)
125 console.debug("plugin blocked request", ctx.pluginBlockedRequest = id)
126 if (typeof res === 'function')