Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mcollina/fastify-undici-dispatcher

An undici dispatcher to in-process Fastify servers
https://github.com/mcollina/fastify-undici-dispatcher

Last synced: 2 days ago
JSON representation

An undici dispatcher to in-process Fastify servers

Awesome Lists containing this project

README

        

# fastify-undici-dispatcher

An undici dispatcher to in-process Fastify servers

## Install

```
npm i fastify fastify-undici-dispatcher undici
```

## Usage as an Interceptor

```js
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

```js
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