Module: request-context

request-context

Module defining a simple interface for setting and getting context objects on a domain. A connect middleware allows wrapping requests in a domain and setting/getting values on the active domain object.
Source:

Requires

  • module:domain

Members

module:request-context :Object

The ContextService provides the middleware and context accessor methods
Type:
  • Object
Source:

<static> get

Alias for the getContext method.
Source:

<static> getContext

Return the context or a context variable for a name or path.
Source:

<static> middleware :function

Wrap the request/response loop in a namespace wrapper (by using node's domain system). All following functions will be run in the created namespace. Returns a function function that can be used as connect middleware.
Type:
  • function
Source:

<static> set

Alias for the setContext method.
Source:

<static> setContext

Set the context for a given name or path.
Source:

Methods

<inner> contextMiddleware(namespace) → {function}

Wrap the request/response loop in a namespace wrapper (by using node's domain system).
Parameters:
Name Type Description
namespace String The name of the namespace to create
Source:
Returns:
A function that can be used as request middleware. Following functions will be run in the created namespace.
Type
function

<inner> getContext(name, current) → {*}

Return the context for a name.
Parameters:
Name Type Argument Description
name String The name of the context to retrieve
current domain <optional>
A domain object to retrieve the context object from
Source:
Returns:
The context for the given name
Type
*

<inner> getCurrent(current) → {null|Object}

Get the current active domain context object
Parameters:
Name Type Argument Description
current domain <optional>
A domain object the context container should be looked upon
Source:
Returns:
Type
null | Object

<inner> getPropertyForPath(obj, path) → {*}

Get the object property for a given path divided by dots
Parameters:
Name Type Description
obj Object The object to query
path String The objects property path divided by dots
Source:
Returns:
Type
*

<inner> initContext(domain) → {Object|*}

Initiates the context object on the provided domain
Parameters:
Name Type Description
domain A domain object to initialize the context object on
Source:
Returns:
Type
Object | *

<inner> normalizePathArray(path) → {*}

Normalize the namespace of a path by replacing all ':' to '.'.
Parameters:
Name Type Description
path String The context object property path divided by dots
Source:
Returns:
Type
*

<inner> setContext(name, value, current)

Set the context for a given name
Parameters:
Name Type Argument Description
name String The name of the context
value * The value to set
current domain <optional>
A domain object to retrieve the context object from
Source:
Throws:
Error

<inner> setPropertyForPath(obj, path, value) → {*}

Set the object property for a given path divided by dots
Parameters:
Name Type Description
obj Object The object to modify
path String The objects property path divided by dots
value * The value to set on the objects path
Source:
Returns:
Type
*