fastify
Version:
Fast and low overhead web framework, for Node.js
46 lines (38 loc) • 829 B
JavaScript
const fastify = require('../fastify')()
const opts = {
schema: {
response: {
200: {
type: 'object',
properties: {
hello: {
type: 'string'
}
}
}
}
}
}
function promiseFunction (resolve) {
setImmediate(resolve)
}
async function asyncHook () {
await new Promise(promiseFunction)
}
fastify
.addHook('onRequest', asyncHook)
.addHook('onRequest', asyncHook)
.addHook('preHandler', asyncHook)
.addHook('preHandler', asyncHook)
.addHook('preHandler', asyncHook)
.addHook('onSend', asyncHook)
fastify.get('/', opts, function (request, reply) {
reply.send({ hello: 'world' })
})
fastify.listen(3000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})