Skip to main content

Minimum Hooks

Prep (start frourio in dev mode)#

Before we create the hooks.ts and start writing the hooks, start frourio in dev mode.

yarn dev:frourio
# or
yarn dev # all

It detects the creation of files, such as hooks.ts, and puts a template in the case of an empty file.

Creation and automatic generation#

For starters, let's create a hooks.ts under /api.

touch server/api/hooks.ts

Then we get a directory level hooks (*later), which is just a console.log as follows.

server/api/hooks.ts
import { defineHooks } from './$relay'
export default defineHooks(() => ({
onRequest: (req, reply, done) => {
console.log('Directory level onRequest hook:', req.url)
done()
}
}))