All Projects → fastify → fast-proxy

fastify / fast-proxy

Licence: MIT license
Node.js framework agnostic library that enables you to forward an http request to another HTTP server. Supported protocols: HTTP, HTTPS, HTTP2

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to fast-proxy

Iot Dc3
IOT DC3 is an open source, distributed Internet of Things (IOT) platform based on Spring Cloud. It is used for rapid development of IOT projects and management of IOT devices. It is a set of solutions for IOT system.
Stars: ✭ 195 (+38.3%)
Mutual labels:  gateway
Qtgate Desktop Client
A revolutionary internet infrastructure enabling a truly free Network, that offers Stability, Trust, Privacy, and Security
Stars: ✭ 232 (+64.54%)
Mutual labels:  gateway
gateway
A high-performance API Gateway with middlewares, supporting HTTP and gRPC protocols.
Stars: ✭ 520 (+268.79%)
Mutual labels:  gateway
Whapp Irc
whatsapp web <-> irc gateway
Stars: ✭ 208 (+47.52%)
Mutual labels:  gateway
Goku Api Gateway
A Powerful HTTP API Gateway in pure golang!Goku API Gateway (中文名:悟空 API 网关)是一个基于 Golang开发的微服务网关,能够实现高性能 HTTP API 转发、服务编排、多租户管理、API 访问权限控制等目的,拥有强大的自定义插件系统可以自行扩展,并且提供友好的图形化配置界面,能够快速帮助企业进行 API 服务治理、提高 API 服务的稳定性和安全性。
Stars: ✭ 2,773 (+1866.67%)
Mutual labels:  gateway
S3auth
Amazon S3 HTTP Basic Auth Gateway
Stars: ✭ 249 (+76.6%)
Mutual labels:  gateway
Product Microgateway
A cloud native, developer centric and decentralized API gateway for microservices
Stars: ✭ 194 (+37.59%)
Mutual labels:  gateway
payum-ecpay
The Payum extension. 綠界金流
Stars: ✭ 13 (-90.78%)
Mutual labels:  gateway
Gateway
A federated api gateway for graphql services. https://gateway.nautilus.dev/
Stars: ✭ 221 (+56.74%)
Mutual labels:  gateway
Springcloudlearning
《史上最简单的Spring Cloud教程源码》
Stars: ✭ 16,218 (+11402.13%)
Mutual labels:  gateway
Siprtcproxy
网关服务:Sip与Rtc互通,实现Web,Android,iOS,小程序,SIP座机,PSTN电话,手机互通。
Stars: ✭ 217 (+53.9%)
Mutual labels:  gateway
Apilogs
Easy logging and debugging for Amazon API Gateway and AWS Lambda Serverless APIs
Stars: ✭ 216 (+53.19%)
Mutual labels:  gateway
Springcloud
springCloud学习
Stars: ✭ 251 (+78.01%)
Mutual labels:  gateway
Brouter
Stars: ✭ 198 (+40.43%)
Mutual labels:  gateway
WHMCS-JSJ-API-Pay-Gateway
WHMCS 财务系统对接金莎云免签支付API(你们怎么用,与我无瓜好吧:)
Stars: ✭ 58 (-58.87%)
Mutual labels:  gateway
Xian
reactive风格的微服务框架
Stars: ✭ 196 (+39.01%)
Mutual labels:  gateway
Mbusd
Open-source Modbus TCP to Modbus RTU (RS-232/485) gateway.
Stars: ✭ 233 (+65.25%)
Mutual labels:  gateway
SmartGW
Domain based VPN Gateway/Proxy for all devices
Stars: ✭ 49 (-65.25%)
Mutual labels:  gateway
citrix-adc-aws-cloudformation
Citrix ADC (Formerly Netscaler) templates and scripts for AWS deployment
Stars: ✭ 11 (-92.2%)
Mutual labels:  gateway
Davmail
DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
Stars: ✭ 250 (+77.3%)
Mutual labels:  gateway

fast-proxy

CI NPM version

Node.js framework agnostic library that enables you to forward an http request to another HTTP server. Supported protocols: HTTP, HTTPS, HTTP2

This library was initially forked from fastify-reply-from: https://github.com/fastify/fastify-reply-from

fast-proxy powers: https://www.npmjs.com/package/fast-gateway 🚀

Install

npm i fast-proxy

Usage

The following examples describe how to use fast-proxy with restana:

Gateway:

const { proxy, close } = require('fast-proxy')({
  base: 'http://127.0.0.1:3000'
  // options
})
const gateway = require('restana')()

gateway.all('/service/*', function (req, res) {
  proxy(req, res, req.url, {})
})

gateway.start(8080)

Remote service:

const service = require('restana')()
service.get('/service/hi', (req, res) => res.send('Hello World!'))

service.start(3000)

Using imports:

import fastProxy from 'fast-proxy'

const { proxy, close } = fastProxy({
  base: 'http://127.0.0.1:3000'
})

Benchmarks

Please see: https://github.com/jkyberneees/nodejs-proxy-benchmarks

API

Options

base

Set the base URL for all the forwarded requests. Will be required if http2 is set to true Note that path will be discarded.

queryString

Set the query string parser and stringifier. By default fast-proxy uses the fast-querystring module. Configuration can be changed like so:

{
  base: 'http://localhost:3001/',
  queryString: {
    parse: (value) => qs.parse(value),
    stringify: (value) => qs.stringify(value),
  }
}

http2

Set to true if target server is http2 enabled.

undici

Set to true to use undici instead of require('http'). Enabling this flag should guarantee 20-50% more throughput.

This flag could controls the settings of the undici client, like so:

...
  base: 'http://localhost:3001/',
  undici: {
    connections: 100,
    pipelining: 10
  }
...

See undici demo at: demos/gateway-undici.js

cacheURLs

The number of parsed URLs that will be cached. Default: 100.

Use value = 0 to disable the caching mechanism

requests.http and requests.https

Allows to optionally overwrite the internal http and https client agents implementation. Defaults: http and https.

For example, this could be used to add support for following redirects, like so:

...
  requests: {
    http: require('follow-redirects/http'),
    https: require('follow-redirects/https')
  }
...

If using undici or http2 this settings are ignored!

keepAliveMsecs

Defaults to 1 minute, passed down to [http.Agent][http-agent] and [https.Agent][https-agent] instances.

maxSockets

Defaults to 2048 sockets, passed down to [http.Agent][http-agent] and [https.Agent][https-agent] instances.

rejectUnauthorized

Defaults to true, passed down to [https.Agent][https-agent] instances. This needs to be set to false to reply from https servers with self-signed certificates.

Extended configurations

Other supported configurations in https://nodejs.org/api/http.html#http_new_agent_options can also be part of the opts object.

close

Optional "on close resource release" strategy. You can link this to your application shutdown hook as an example.

proxy(originReq, originRes, source, [opts])

Enables you to forward an http request to another HTTP server.

proxy(
  originReq,                          // http.IncomingMessage 
  originRes,                          // http.ServerResponse
  req.url,                            // String -> remote URL + path or path if base was set
  {}                                  // Options described below
)

opts

base

Optionally indicates the base URL for the current request proxy. When used, the global base config is overwriten.

This configuration value is ignored when using HTTP2.

onResponse(req, res, stream)

Called when an http response is received from the source. The default behavior is pump(stream, res), which will be disabled if the option is specified.

rewriteRequestHeaders(req, headers)

Called to rewrite the headers of the request, before them being sent to the downstream server. It must return the new headers object.

rewriteHeaders(headers)

Called to rewrite the headers of the response, before them being copied over to the outer response. It must return the new headers object.

request

Extended options supported by http[s].request method (https://nodejs.org/api/http.html#http_http_request_options_callback) The following options are dynamically assigned: method, port, path, hostname, headers, agent.

http2 options are limited to timeout only, while undici supports none.

queryString

Replaces the original querystring of the request with what is specified. This will get passed to querystring.stringify.

Related topics

Contributions

Special thanks to fastify-reply-from developers for creating a production ready library from where we could initially fork.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].