2.1.0 • Published 2 months ago

proxyy v2.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 months ago

proxyy

A http(s) proxy middleware

npm-badge actions-badge

Non-transparent http(s) proxy connect middleware with the ability to rewrite location headers and cookies.

Does:

  • Adds X-Forwarded-For header entry.
  • Copes with connection errors and timeouts.
  • URL rewriting in HTML pages
  • Rewrites Location headers
  • Rewrites Cookie Domains and Paths (follows nginx.org approach)
  • Rewrites Referer request headers

Why another proxy middleware? Check-out:

API

For all possible options related to http/https see

Parameters

parametertypedescription
[url]Stringoptional: base url to proxy
[options]Objectoptional: http, https options
options.methodStringupercase HTTP method
options.protocolStringhttp: or https: see url.parse()
options.hostnameStringhostname
options.portStringport
options.pathStringpath
[options.timeout=5000]Numberoptional: timeout in (ms) default=5000
[option.onResponse]Functionoptional: function (clientRes, res) allows to change statuscode and/or headers
[option.baseUrl]Stringoptional: baseUrl of routed request, comes usually from express
[options.cookieDomains]Arrayoptional: see example
[options.cookiePaths]Arrayoptional: see example
[options.preserveHost=false]Booleanoptional: if true request host header is preserved
[option.isForwarded=false]Booleanoptional: request was forwarded from other server which set x-forwarded-host and x-forwarded-proto headers
[option.noHtmlRewrite=false]Booleanoptional: Do not rewrite html/ xml responses

Examples

With Url

const proxy = require('proxyy')
const app = require('express')()

app.use('/api', proxy('https://server.my')
app.listen(3000)

//> proxies 'http://localhost:3000/api/path' to 'https://server.my/path'

With options and legacy server

const http = require('http')

http.createServer(proxy({
  baseUrl: '/proxied',  // if using `express` 'baseUrl' is handled via express routing
                        // so no need to set this with `express`
  protocol: 'http:',
  host: 'server.my',
  port: '4000',
  path: '/api',
  timeout: 5000
})).listen(3000)

//> proxies 'http://localhost:3000/proxied/path' to 'http://server.my:4000/api/path'

Rewriting Cookies

// proxy DNS is 'proxy.my'
app.use('/api', proxy(
  'https://api.server.my/path', {
    cookieDomains: [
      ['www.server.my', 'www.proxy.my'], // replace string by string
      [/^(\w+)\.server.com/, '$1.proxy.my'] // replace using regex
    ],
    cookiePaths: [
      ['/path', '/'], // replace string by string
      [/^(\w+)\/path(\/\w+)/, '$1$2'] // replace using regex
    ]
  }
))

//> Domain=www.server.my;  --> Domain=www.proxy.my;
//> Domain=api.server.com; --> Domain=api.proxy.my;

//> Path=/path;       --> Path=/;
//> Path=/a/path/doc; --> Path=/a/doc;

Installation

Requires nodejs.

$ npm install proxyy --save

Tests

$ npm test

License

MIT Licensed

2.1.0

2 months ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago