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.
Requires
- module:domain
Members
-
module:request-context :Object
-
The ContextService provides the middleware and context accessor methods
Type:
- Object
-
<static> get
-
Alias for the getContext method.
-
<static> getContext
-
Return the context or a context variable for a name or path.
-
<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
-
<static> set
-
Alias for the setContext method.
-
<static> setContext
-
Set the context for a given name or path.
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 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 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 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 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 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 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 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 Returns:
- Type
- *