Helma Logo
main list history
previous version  overview  next version

Version 3 by hannes on 18. June 2009, 20:20

Middleware is feature of the Helma NG webapp framework that provides a simple interface to inject additional code between the web server and the web application. Middleware uses the same calling conventions as web app actions: a function that takes a Request object as argument and returns a Response object.

Since middleware wraps the web application (and any middlware stacked upon it), it is in full control of how the request is processed.

* Inspect and modify the request object before processing it further
* Decide not to pass the request on, returning its own response instead
* Inspect and modify the response obtained from the application

Middleware is configured in an exported Array called <code>middleware</code> in the app's <code>config</code> module. By convention, the webapp looks for a function called <code>handleRequest</code> in middleware modules.

The <code>request</code> argument contains a <code>process</code> method that is used to pass the request on in the middleware chain. Thus, a middleware implementation that just passes on the request might look like this:

  exports.handleRequest(req) {
    return req.process();

Have a look at the *modules/helma/middlware|https://dev*modules/helma/middlware|http://github.helma.org/trac/helma/browser/helma-ng/trunk/modules/helma/middleware* com/hns/helma-ng/tree/master/modules/helma/middleware* directory for the standard middleware currently shipping with Helma NG.