Skip to content

lmammino/fastify-http-proxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-http-proxy

Greenkeeper badge

Build Status

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.

Install

npm i fastify-http-proxy fastify

Example

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.

Options

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.

upstream

The target server to use for proxying

prefix

The prefix to mount this plugin on. This is provided by fastify itself.

beforeHandler

A beforeHandler to be applied on all routes. Useful for performing authentication.

http2

A beforeHandler to be applied on all routes. Useful for performing authentication.

Benchmarks

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.

TODO

  • Generate unique request ids and implement request tracking
  • Perform validations for incoming data

License

MIT

About

Proxy your http requests to another server, with hooks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%