0.7.0 • Published 10 months ago

fastify-undici-dispatcher v0.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

fastify-undici-dispatcher

An undici dispatcher to in-process Fastify servers

Install

npm i fastify fastify-undici-dispatcher undici

Usage as an Interceptor

const { request, Agent } = require('undici')
const { createFastifyInterceptor } = require('fastify-undici-dispatcher')
const Fastify = require('fastify')
const server = Fastify()
server.get('/', async (req, reply) => {
  return 'hello world'
})

const interceptor = createFastifyInterceptor({
  domain: '.local' // optional
})

const dispatcher = new Agent().compose(interceptor)
dispatcher.route('myserver', server)

request('http://myserver.local', {
  dispatcher
}).then((res) => {
  return res.body.text()
}).then(console.log)

Usage as a Dispatcher

const { request, Agent } = require('undici')
const FastifyUndiciDispatcher = require('fastify-undici-dispatcher')
const Fastify = require('fastify')
const server = Fastify()
server.get('/', async (req, reply) => {
  return 'hello world'
})

const dispatcher = new FastifyUndiciDispatcher({
  dispatcher: new Agent(), // optional
  domain: '.local' // optional
})
dispatcher.route('myserver', server)

request('http://myserver.local', {
  dispatcher
}).then((res) => {
  return res.body.text()
}).then(console.log)

License

MIT

0.7.0

10 months ago

0.6.0

1 year ago

0.5.1

1 year ago

0.5.0

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago

0.1.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago