Directory-level hooks

Directory-level hooks are called at the current and subordinate endpoints.

Fastify hooks

server/api/tasks/hooks.ts
import { defineHooks } from './$relay' // '$relay.ts' is automatically generated by frourio
export default defineHooks(() => ({
onRequest: [
(req, reply, done) => {
console.log('Directory-level onRequest first hook:', req.url)
done()
},
(req, reply, done) => {
console.log('Directory-level onRequest second hook:', req.url)
done()
}
],
preParsing: (req, reply, payload, done) => {
console.log('Directory-level preParsing single hook:', req.url)
done()
}
}))

info

Directory-level hooks are cascading, so server/api/hooks.ts is effectively Global Hooks.