plugins: backend event "request"
Massimo Melina committed
Mar 13, 2026 at 13:04 UTC
743d0736f2fc0ec7622086a4430b8a2dd5b41cb2
2 files changed
+11
-1
dev-plugins.md
+6
-1
@@ -834,6 +834,11 @@ This section is still partially documented, and you may need to have a look at t
834
- `who: Who` is like `node[perm]`, that is the configured permission on the node,
835
but without references to other permissions or the object form, as they have already been translated
836
- return: an http error as number >= 400, or 0 or undefined
837
+- `request` called for every incoming HTTP request, as an alternative to plugin `middleware` callbacks
838
+ - parameters: { ctx }
839
+ - async supported
840
+ - preventable
841
+ - return: callback(s) to run after request handling is completed, similar to `middleware` upstream
842
843
# Notifications (backend-to-frontend events)
844
@@ -1178,4 +1183,4 @@ If you want to override a text regardless of the language, use the special langu
1183
- 12.97 (v0.57.28)
1184
- HFS.customizeText
1185
- 13 (v3.1.0)
1181
- - backend event: dirEntry
\ No newline at end of file
1186
+ - backend events: dirEntry, request
\ No newline at end of file
src/plugins.ts
+5
@@ -179,6 +179,11 @@ export const pluginsMiddleware: Koa.Middleware = async (ctx, next) => {
179
// run middleware plugins
180
let lastStatus = ctx.status
181
let lastBody = ctx.body
182
+ const res = await events.emitAsync('request', { ctx })
183
+ if (ctx.isAborted() || res?.isDefaultPrevented())
184
+ return
185
+ if (res?.length)
186
+ after['/event'] = () => res.forEach(callable)
187
await Promise.all(mapPlugins(async (pl, id) => {
188
try {
189
const res = await pl.middleware?.(ctx)