plugins: event 'spam'

Massimo Melina committed May 20, 2024 at 10:04 UTC 939fbe651b69fe8b38c20aaf3352750eaaaddb1a
1 file changed +5 -1
src/log.ts
+5 -1
@@ -77,7 +77,10 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
77 await next()
78 console.debug(ctx.status, ctx.method, ctx.originalUrl)
79 if (ctx.status === HTTP_NOT_FOUND && !logSpam.get()
80 - && /wlwmanifest.xml$|robots.txt$|\.(php)$|cgi/.test(ctx.path)) return
80 + && /wlwmanifest.xml$|robots.txt$|\.(php)$|cgi/.test(ctx.path)) {
81 + events.emit('spam', ctx)
82 + return
83 + }
84 const conn = getConnection(ctx) // collect reference before close
85 // don't await, as we don't want to hold the middlewares chain
86 ctx.state.completed.then(() => {
@@ -146,6 +149,7 @@ declare module "koa" {
149 dontLog?: boolean // don't log this request
150 logExtra?: object
151 completed?: Promise<unknown>
152 + spam?: boolean // this request was marked as spam
153 }
154 }
155