ProxyServer

SGAppsProxy. ProxyServer

new ProxyServer()

Source:

Methods

(static) protocol(defaultProtocolopt) → {string}

returns current used protocol

.

Source:

returns current used protocol

Parameters:
Name Type Attributes Description
defaultProtocol string <optional>

if is empty returns configuration default protocol

Returns:
Type
string

close(cb)

close ProxyServer

.

Source:

close ProxyServer

Parameters:
Name Type Description
cb function

callback receives an error if it occurs

configuration() → {SGAppsProxy.Config}

returns proxy current configuration

.

Source:

returns proxy current configuration

Returns:
Type
SGAppsProxy.Config

debugEnabled() → {boolean}

check if debug mode is enabled

.

Source:

check if debug mode is enabled

Returns:
Type
boolean

debugEnabled(status) → {boolean}

enable disable debug mode

.

Source:

enable disable debug mode

Parameters:
Name Type Description
status boolean
Returns:
Type
boolean

error(err)

log a error if debug mode is enabled

.

Source:

log a error if debug mode is enabled

Parameters:
Name Type Description
err Error

handleRequest(request, response)

handle for http server request / response

.

Source:

handle for http server request / response

Parameters:
Name Type Description
request Request
response Response

httpServer() → {object}

returns http server user by ProxyServer return type Server

.

Source:

returns http server user by ProxyServer return type Server

Returns:
Type
object

isRunning() → {boolean}

check if ProxyServer is running, it returns null if no http server is attached to ProxyServer

.

Source:

check if ProxyServer is running, it returns null if no http server is attached to ProxyServer

Returns:
Type
boolean

log(…items)

logs if debug mode is enabled

.

Source:

logs if debug mode is enabled

Parameters:
Name Type Attributes Description
items any <repeatable>

proxyServer() → {ProxyServer}

return proxy instance

.

Source:

return proxy instance

Returns:
Type
ProxyServer

responseRenderPath(response, path)

render a file in response, file piped to response

.

Source:

render a file in response, file piped to response

Parameters:
Name Type Description
response Response
path string

string2Rule(rule) → {RegExp}

converts a string rule into regular expression ( case sensitive )

.

Source:

converts a string rule into regular expression ( case sensitive )

Parameters:
Name Type Description
rule string

example "*.sgapps.io"

Returns:
Type
RegExp

Type Definitions

Cache

Source:
Properties:
Name Type Description
question object

appear after events proxy-upgrade or http-request

Properties
Name Type Description
pathname string
url string
domain string
parsedUrl SGAppsProxy.ParsedUrl
result Array.<SGAppsProxy.ProxyRule>
Type:
  • object

Events

http-request

event id is "http-request--question-constructor"

.

Source:

event id is "http-request--question-constructor"

Parameters:
Name Type Description
request Request
response Response
cache module:SGAppsProxy.ProxyServer.Cache
Fires:

http-request-prepared

event id is "proxy-handler"

.

Source:

event id is "proxy-handler"

Parameters:
Name Type Description
request Request
response Response
cache module:SGAppsProxy.ProxyServer.Cache
Fires:

listening

event id is proxy-upgrade-handler

.

Source:

event id is proxy-upgrade-handler

Parameters:
Name Type Description
port number
host string

proxy-error

event is emitted by ProxyInstance

.

Source:

event is emitted by ProxyInstance

Parameters:
Name Type Description
err Error
request Request
response Response

proxy-request

event id is "question-handler"

.

Source:

event id is "question-handler"

Parameters:
Name Type Description
proxyRequest Request
request Request
response Response
options object
Fires:

proxy-upgrade

event id is proxy-upgrade-handler

.

Source:

event id is proxy-upgrade-handler

Parameters:
Name Type Description
request Request
response Response
head object

http's server update header http#upgrade event

Fires:

question-request

event id is "question-handler"

.

Source:

event id is "question-handler"

Parameters:
Name Type Description
request Request
response Response
cache module:SGAppsProxy.ProxyServer.Cache
Fires:

question-websocket-request

event id is "question-websocket-handler"

.

Source:

event id is "question-websocket-handler"

Parameters:
Name Type Description
request Request
response Response
cache module:SGAppsProxy.ProxyServer.Cache
Fires:

websocket-request-prepared

event id is "proxy-handler-websocket"

.

Source:

event id is "proxy-handler-websocket"

Parameters:
Name Type Description
request Request
response Response
head object
cache module:SGAppsProxy.ProxyServer.Cache