app.js
* Worker Default App Enhancements
* @module greppy/app/worker/app
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* @param {Object} worker - Worker object
this.context = worker.context;
this.contexts = greppy.config.get('app').get('infrastructure');
App.prototype.rebuildLinkingCache = function()
// Build an controller names cache of all
// registered routes of the worker context
this.context.routes.forEach(function(route) {
self.controllers[route.controllerPath] = route.thisArg;
* Build a link to a controller action.
* @param {String} controller - Controller path (eg. admin.users)
* @param {String} action - Name of the action to link to
* @param {Object} params - Parameters object
* @param {String} [absoluteUrl] - If given, it will be prefixed
App.prototype.link = function(controller, action, params, absoluteUrl)
if (!this.controllers.hasOwnProperty(controller)) {
'Controller path "%s" is not registered. ' +
'The following controller paths are registered: \n * %s'.format(
Object.keys(this.controllers).join('\n * ')
return this.controllers[controller].link(action, params, absoluteUrl);
* @param {String} context - Name of the context
* @param {String} [path] - Path to suffix to the context link
App.prototype.linkContext = function(context, path)
if (!this.contexts.hasOwnProperty(context)) {
'Context "%s" is not registered.'.format(context)
var url = this.contexts[context].url || '/';
// Add trailing slash if not yet present
// Remove leading slash of path if given
path = path.replace(/\/+/gi, '/')
* Pre-Configure the given objects.
* @param {Object} app - Application to configure
* @param {Object} server - Server to configure
* @param {function} callback - Function to call on finish
App.prototype.preConfigure = function(app, server, callback)
// @DEPRECATED: Remove this with Greppy 0.9
(new (require('./middleware/default'))()).configure(
(new (require('./base/parameter'))()).configure(
(new (require('./base/view-helpers'))()).configure(
* Configure the given objects to fit the Greppy needs.
* @param {Object} app - Application to configure
* @param {Object} server - Server to configure
* @param {function} callback - Function to call on finish
App.prototype.configure = function(app, server, callback)
(new (require('./middleware/request'))(self)).configure(
(new (require('./middleware/app'))(self)).configure(
* Post configure the given objects to fit the Greppy needs.
* @param {Object} app - Application to configure
* @param {Object} server - Server to configure
* @param {function} callback - Function to call on finish
App.prototype.postConfigure = function(app, server, callback)