Constructor
new JsonCachingProxy(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | Options passed into the ctor will override defaults if defined |
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.
Returns:
- Type
- JsonCachingProxy
addBodyParser() → {JsonCachingProxy}
Add Request body parsing into RAW if there is actual body content
Returns:
- Type
- JsonCachingProxy
addCachingRoute() → {JsonCachingProxy}
An express route that reads from the cache if possible for any routes persisted in cache memory
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 |
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 |
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.
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 |
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) |
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 |
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 |
Returns:
A unique key, hash tuple that identifies the request
- Type
- Object
getApp() → {Object}
Returns the Express App
Returns:
- Type
- Object
getDefaultOptions() → {Object}
Returns the default options that are used when no options are passed in
Returns:
- Type
- Object
getExcludedParamMap() → {Object}
Returns the key value map of all the excluded params
Returns:
- Type
- Object
getOptions() → {Object}
Returns the options passed into the proxy
Returns:
- Type
- Object
getServer() → {Object}
Returns the Node server object
Returns:
- Type
- Object
getTotalCachedRoutes() → {number}
Count of total cached routes in memory
Returns:
- Type
- number
isRecording() → {JsonCachingProxy}
Is the server saving to the cache
Returns:
- Type
- JsonCachingProxy
isReplaying() → {boolean}
Is the server sending us cached responses
Returns:
- Type
- boolean
isRouteCacheEmpty() → {boolean}
Determines if we have anything in the cache
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 |
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
Parameters:
Name | Type | Description |
---|---|---|
cookies |
Object | Express cookies array |
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 |
Returns:
- Type
- JsonCachingProxy
stop(callback) → {JsonCachingProxy}
Stops the proxy server
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | fn executed after the server has stopped |
Returns:
- Type
- JsonCachingProxy