generated from fastify/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
36 lines (28 loc) · 853 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const fastify = require('fastify')({ logger: true, connectionTimeout: 2000 })
const dc = require('node:diagnostics_channel')
const channels = [
dc.channel('fastify.onRoute'),
dc.channel('fastify.onTimeout'),
dc.channel('fastify.onError'),
dc.channel('fastify.onResponse'),
dc.channel('fastify.onRequest')
]
channels.forEach(channel => {
channel.subscribe((message, name) => {
console.info('Triggered:', name, message)
})
})
fastify.register(require('../lib/index'))
fastify.get('/params/:id', (_request, reply) => {
reply.send({})
})
fastify.get('/error', (_request, _reply) => {
throw new Error('error example')
})
fastify.get('/timeout', async (_request, _reply) => {
await new Promise((resolve) => setTimeout(resolve, 5000))
})
fastify.listen({ port: 3000 }, '0.0.0.0', (err) => {
if (err) throw err
})