Add app.utility to register utility functions by name
This commit is contained in:
parent
7c96aec9af
commit
087f353af1
|
@ -243,6 +243,21 @@ app.connector = function(name, connector) {
|
|||
this.connectors[camelize(name)] = connector;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a utility function with the given name
|
||||
*
|
||||
* The utilities will be used to resolve functions by name so that functions can
|
||||
* be referenced in JSON configuration files, for example, the default value
|
||||
* function, the middleware handler, or the validator
|
||||
* @param {String} name The utility name
|
||||
* @param {Function} fn The handler
|
||||
*/
|
||||
app.utility = function(name, fn) {
|
||||
assert(typeof name === 'string', 'Utility function name must be a string');
|
||||
assert(typeof fn === 'function', 'The utility must be a function');
|
||||
this.utilities[name] = fn;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all remote objects.
|
||||
* @returns {Object} [Remote objects](http://apidocs.strongloop.com/strong-remoting/#remoteobjectsoptions).
|
||||
|
|
|
@ -75,6 +75,8 @@ function createApplication() {
|
|||
app.connector('memory', loopback.Memory);
|
||||
app.connector('remote', loopback.Remote);
|
||||
|
||||
app.utilities = {};
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue