Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ For other examples, see `example.js`.

## Options

This `fastify` plugin supports the following options.
This `fastify` plugin supports _all_ the options of
[`fastify-reply-from`](https://github.com/fastify/fastify-reply-from) plus the following.

*Note that this plugin is fully encapsulated, and non-JSON payloads will
be streamed directly to the destination.*
Expand All @@ -82,10 +83,6 @@ The prefix to mount this plugin on. All the requests to the current server start

A `beforeHandler` to be applied on all routes. Useful for performing actions before the proxy is executed (e.g. check for authentication).

### http2

A boolean value that indicates whether the proxy should support http2.

## Benchmarks

The following benchmarks where generated on a Macbook 2018 with i5 and
Expand All @@ -95,6 +92,8 @@ The following benchmarks where generated on a Macbook 2018 with i5 and
| `express-http-proxy` | 878.4 |
| `http-proxy` | 3837 |
| `fastify-http-proxy` | 4205 |
| `fastify-http-proxy` (with
[`undici`](https://github.com/mcollina/undici)) | 6235.6 |

The results where gathered on the second run of `autocannon -c 100 -d 5
URL`.
Expand Down
12 changes: 11 additions & 1 deletion benchmarks/fastify-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ const proxy = require('..')

async function startProxy (upstream) {
const server = Fastify()
let undici = false

if (process.env.UNDICI) {
undici = {
connections: 100,
pipelining: 10
}
}

server.register(proxy, {
upstream,
http2: !!process.env.HTTP2
http2: !!process.env.HTTP2,
undici
})

await server.listen(3000)
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module.exports = async function (fastify, opts) {

const beforeHandler = opts.beforeHandler

fastify.register(From, {
base: opts.upstream,
http2: opts.http2
})
const fromOpts = Object.assign({}, opts)
fromOpts.base = opts.upstream
fromOpts.prefix = undefined

fastify.register(From, fromOpts)

fastify.addContentTypeParser('application/json', bodyParser)
fastify.addContentTypeParser('*', bodyParser)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"tap": "^12.0.0"
},
"dependencies": {
"fastify-reply-from": "^0.4.5"
"fastify-reply-from": "^0.5.0"
}
}