SGAppsProxy

SGAppsProxy

Source:

Type Definitions

Config

Source:
Properties:
Name Type Attributes Default Description
defaultProtocol string <optional>
'http'
secureVerify boolean <optional>
true
proxyRules Array.<SGAppsProxy.ProxyRule>
httpServer object <optional>
Properties
Name Type Description
host string
port number
debug boolean <optional>
true
Type:
  • object

ParsedUrl

Source:
Properties:
Name Type Description
protocol string

( ex: 'https:' )

slashes boolean

( ex: true )

auth string

( ex: null or 'username:password' )

host string

( ex: 'sgapps.io:808' )

port string

( ex: '808' )

hostname string

( ex: 'sgapps.io' )

hash string

( ex: '#23' )

search string

( ex: '?query=234' )

query string

( ex: 'query=234' )

pathname string

( ex: '/path' )

path string

( ex: '/path?query=234' )

href string

( ex: 'https://sgapps.io:808/path?query=234#23' )

Type:
  • object

ProxyFilter(proxyRefs, proxyOptions, request, response, rule, cache) → {Promise.<(null|true|false)>}

if returns null the proxy server will not continue to parse flow if returns false the proxy server will ignore rule if returns true the proxy server will accept rule if returns Error the proxy will accept render error page

.

Source:

if returns null the proxy server will not continue to parse flow if returns false the proxy server will ignore rule if returns true the proxy server will accept rule if returns Error the proxy will accept render error page

Parameters:
Name Type Description
proxyRefs object
proxyOptions SGAppsProxy.ProxyOptions
request Request
response Response
rule SGAppsProxy.ProxyRule
cache SGAppsProxy.ProxyServer.Cache
Returns:
Type
Promise.<(null|true|false)>

ProxyOptions

Source:
Properties:
Name Type Attributes Description
target string <optional>

url string to be parsed with the url module

forward string <optional>

url string to be parsed with the url module

agent object <optional>

object to be passed to http(s).request (see Node's https agent and http agent objects)

ssl object <optional>

object to be passed to https.createServer()

ws boolean <optional>

true/false, if you want to proxy websockets

xfwd boolean <optional>

true/false, adds x-forward headers

secure boolean <optional>

true/false, if you want to verify the SSL Certs

toProxy boolean <optional>

true/false, passes the absolute URL as the path (useful for proxying to proxies)

prependPath boolean <optional>

true/false, Default: true - specify whether you want to prepend the target's path to the proxy path

ignorePath boolean <optional>

true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request (note: you will have to append / manually if required).

localAddress string <optional>

Local interface string to bind for outgoing connections

changeOrigin boolean <optional>

true/false, Default: false - changes the origin of the host header to the target URL

preserveHeaderKeyCase boolean <optional>

true/false, Default: false - specify whether you want to keep letter case of response header key

auth string <optional>

Basic authentication i.e. 'user:password' to compute an Authorization header.

hostRewrite boolean <optional>

rewrites the location hostname on (201/301/302/307/308) redirects.

autoRewrite boolean <optional>

rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.

protocolRewrite boolean <optional>

rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.

cookieDomainRewrite boolean <optional>

rewrites domain of set-cookie headers. Possible values: false (default): disable cookie rewriting String: new domain, for example cookieDomainRewrite: "new.domain". To remove the domain, use cookieDomainRewrite: "". Object: mapping of domains to new domains, use "*" to match all domains. For example keep one domain unchanged, rewrite one domain and remove other domains:

    cookieDomainRewrite: {
      "unchanged.domain": "unchanged.domain",
      "old.domain": "new.domain",
      "*": ""
    }
cookiePathRewrite boolean <optional>

rewrites path of set-cookie headers. Possible values: false (default): disable cookie rewriting String: new path, for example cookiePathRewrite: "/newPath/". To remove the path, use cookiePathRewrite: "". To set path to root use cookiePathRewrite: "/". Object: mapping of paths to new paths, use "*" to match all paths. For example, to keep one path unchanged, rewrite one path and remove other paths:

    cookiePathRewrite: {
      "/unchanged.path/": "/unchanged.path/",
      "/old.path/": "/new.path/",
      "*": ""
    }
headers object <optional>

object with extra headers to be added to target requests.

proxyTimeout number <optional>

timeout (in milliseconds) for outgoing proxy requests

timeout number <optional>

timeout (in milliseconds) for incoming requests

followRedirects boolean <optional>

true/false, Default: false - specify whether you want to follow redirects

selfHandleResponse boolean <optional>

true/false, if set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event

buffer Buffer <optional>

stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.g. If you read the body of a request into a field called 'req.rawbody' you could restream this field in the buffer option:

'use strict';

const streamify = require('stream-array');
const HttpProxy = require('http-proxy');
const proxy = new HttpProxy();

module.exports = (req, res, next) => {

  proxy.web(req, res, {
    target: 'http://localhost:4003/',
    buffer: streamify(req.rawBody)
  }, next);

};
response object <optional>
Properties
Name Type Description
headers object

headers to be merger to response headers

Type:
  • object

ProxyOptionsHandler(proxyOptions, request, response, cache) → {SGAppsProxy.ProxyOptions|null}

if returns null the proxy server will not continue to parse flow

.

Source:

if returns null the proxy server will not continue to parse flow

Parameters:
Name Type Description
proxyOptions SGAppsProxy.ProxyOptions
request Request
response Response
cache SGAppsProxy.ProxyServer.Cache
Returns:
Type
SGAppsProxy.ProxyOptions | null

ProxyRule

Source:
Properties:
Name Type Attributes Default Description
client_host string

( ex: '127.0.0.1' )

client_port number

( ex: 80 )

domains Array.<string>

array or domain mappers ( ex: "*.sgapps.io" )

client_path string <optional>
''

( ex: '/some/path/' )

protocol string | 'http' | 'https' <optional>
'http'

( ex: null or 'username:password' )

proxyFilter SGAppsProxy.ProxyFilter
proxyRefs object
proxyOptions SGAppsProxy.ProxyOptions
proxyOptionsHandler SGAppsProxy.ProxyOptionsHandler
Type:
  • object