Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mcollina/fastify-undici-dispatcher
- Owner: mcollina
- License: mit
- Created: 2023-04-11T21:03:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-18T22:47:15.000Z (21 days ago)
- Last Synced: 2024-12-31T03:10:20.040Z (9 days ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 24
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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