Proxy your http requests to another server, with hooks.
This fastify plugin forward all the request
received with a given prefix (or none) to an upstream. All Fastify hooks are still applied.
fastify-http-proxy is built on top of
fastify-reply-from, which enables
you for single route proxying.
npm i fastify-http-proxy fastify
const Fastify = require('fastify')
const server = Fastify()
server.register(require('fastify-http-proxy'), {
upstream,
prefix: '/upstream', // optional
http2: false // optional
})
server.listen(3000)For a more complete example, see example.js.
This fastify plugin supports the following options.
Note that this plugin is fully encapsulated, and non-JSON payloads will
be streamed directly to the destination.
The target server to use for proxying
The prefix to mount this plugin on. This is provided by fastify itself.
A beforeHandler to be applied on all routes. Useful for performing
authentication.
A beforeHandler to be applied on all routes. Useful for performing
authentication.
The following benchmarks where generated on a Macbook 2018 with i5 and 8GB of RAM:
| Framework | req/sec |
| express-http-proxy | 878.4 |
| http-proxy | 3837 |
| fastify-http-proxy | 4205 |
The results where gathered on the second run of autocannon -c 100 -d 5 URL.
- Generate unique request ids and implement request tracking
- Perform validations for incoming data
MIT