Fastify plugin to call self method.
npm i fastify-call --save
'use strict'
const fastify = require('fastify')()
fastify.register(require('fastify-call'))
fastify.get('/t1', function (request, reply) {
reply.send({ 'hello': 't1' })
})
fastify.get('/t2', function (request, reply) {
return fastify.call('t1').then((data) => {
data.world = 't2'
return reply.send(data)
})
})
fastify.get('/t3', function (request, reply) {
return fastify.call.post('t1', { a: 1 }).then((data) => {
data.world = 't3'
return reply.send(data)
})
})
fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})