UNPKG

968 BJavaScriptView Raw
1'use strict'
2
3const fastify = require('../fastify')()
4
5const opts = {
6 schema: {
7 response: {
8 200: {
9 type: 'object',
10 properties: {
11 hello: {
12 type: 'string'
13 }
14 }
15 }
16 }
17 }
18}
19
20fastify
21 .addHook('onRequest', function (request, reply, next) {
22 next()
23 })
24 .addHook('onRequest', function (request, reply, next) {
25 next()
26 })
27
28fastify
29 .addHook('preHandler', function (request, reply, next) {
30 next()
31 })
32 .addHook('preHandler', function (request, reply, next) {
33 setImmediate(next)
34 })
35 .addHook('preHandler', function (request, reply, next) {
36 next()
37 })
38
39fastify
40 .addHook('onSend', function (request, reply, payload, next) {
41 next()
42 })
43
44fastify.get('/', opts, function (request, reply) {
45 reply.send({ hello: 'world' })
46})
47
48fastify.listen(3000, function (err) {
49 if (err) {
50 throw err
51 }
52 console.log(`server listening on ${fastify.server.address().port}`)
53})