Class: JsonCachingProxy

JsonCachingProxy(options)

The caching proxy server.

Constructor

new JsonCachingProxy(options)

Parameters:
Name Type Description
options Object Options passed into the ctor will override defaults if defined
Source:

Methods

addAdminRoutes() → {JsonCachingProxy}

Add the admin express routes for controlling the proxy server through a browser. Allows one to make GET requests to clear the cache, disable/enable playback/recording, and generate a har file of the cache to download for later use.
Source:
Returns:
Type
JsonCachingProxy

addBodyParser() → {JsonCachingProxy}

Add Request body parsing into RAW if there is actual body content
Source:
Returns:
Type
JsonCachingProxy

addCachingRoute() → {JsonCachingProxy}

An express route that reads from the cache if possible for any routes persisted in cache memory
Source:
Returns:
Type
JsonCachingProxy

addHarEntriesToCache(harObject) → {JsonCachingProxy}

Add express routes for each entry in a harObject. The harObject would have been read in from a har file at some point
Parameters:
Name Type Description
harObject Object A standard HAR file object that contains a collection of entries
Source:
Returns:
Type
JsonCachingProxy

addMiddleWareRoutes(middlewareList) → {JsonCachingProxy}

Add user supplied middleware routes to express in order to handle special cases (browser-sync middleware options)
Parameters:
Name Type Description
middlewareList Array.<Object> A list of route/handler pairs
Source:
Returns:
Type
JsonCachingProxy

addProxyRoute() → {JsonCachingProxy}

Add the proxy route that makes the actual request to the target server and cache the response when it comes back. Modifies locations on redirects.
Source:
Returns:
Type
JsonCachingProxy

convertToNameValueList(obj) → {Array.<Object>}

Returns an Object's own properties into an array of name-value pair objects
Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Array.<Object>

createHarEntry(startedDateTime, req, res, data) → {Object}

Build a HAR entry object from an express Request and response
Parameters:
Name Type Description
startedDateTime string An ISO Datetime String
req Object An express IncomingMessage request
res Object An express ServerResponse response
data Object An express response body (the content)
Source:
Returns:
A HAR entry object
Type
Object

genKeyFromExpressReq(req) → {string}

Takes a generic express request and convert it into a HAR request so that a unique key can be generated
Parameters:
Name Type Description
req Object An express IncomingMessage request
Source:
Returns:
A unique hash key that identifies the request
Type
string

genKeyFromHarReq(harEntryReq) → {Object}

Generate a unique hash key from a har file entry's request object: TODO: Include headers?
Parameters:
Name Type Description
harEntryReq Object HAR request object
Source:
Returns:
A unique key, hash tuple that identifies the request
Type
Object

getApp() → {Object}

Returns the Express App
Source:
Returns:
Type
Object

getDefaultOptions() → {Object}

Returns the default options that are used when no options are passed in
Source:
Returns:
Type
Object

getExcludedParamMap() → {Object}

Returns the key value map of all the excluded params
Source:
Returns:
Type
Object

getOptions() → {Object}

Returns the options passed into the proxy
Source:
Returns:
Type
Object

getServer() → {Object}

Returns the Node server object
Source:
Returns:
Type
Object

getTotalCachedRoutes() → {number}

Count of total cached routes in memory
Source:
Returns:
Type
number

isRecording() → {JsonCachingProxy}

Is the server saving to the cache
Source:
Returns:
Type
JsonCachingProxy

isReplaying() → {boolean}

Is the server sending us cached responses
Source:
Returns:
Type
boolean

isRouteCacheEmpty() → {boolean}

Determines if we have anything in the cache
Source:
Returns:
Type
boolean

isRouteExcluded(method, uri) → {boolean}

Check to see if the pieces of a request are excluded. This checks only the method and the uri. It uses the list of regExp matchers to test
Parameters:
Name Type Description
method string e.g. GET, POST, PUT, etc.
uri string e.g. http://www.api.com/rest/accounts
Source:
Returns:
Whether the test is true for some matcher
Type
boolean

removeCookiesDomain(cookies) → {Array.<Object>}

Remove the domain portion of any cookies from the object. Remove the secure attribute so we can set cookies to https targets
Parameters:
Name Type Description
cookies Object Express cookies array
Source:
Returns:
- Cookies with domain portion removed
Type
Array.<Object>

start(callback) → {JsonCachingProxy}

Start the server and generate any log output if needed
Parameters:
Name Type Description
callback function fn executed after the server has started
Source:
Returns:
Type
JsonCachingProxy

stop(callback) → {JsonCachingProxy}

Stops the proxy server
Parameters:
Name Type Description
callback function fn executed after the server has stopped
Source:
Returns:
Type
JsonCachingProxy