Helma Logo
main list history

Version 5 by hannes on 12. November 2009, 14:03

21The above list shows some of the middleware that comes with Helma NG. Have a look at the [modules/helma/middlware][http://github[modules/helma/middlware](http://github.com/hns/helma-ng/tree/master/modules/helma/middleware] com/hns/helma-ng/tree/master/modules/helma/middleware) directory for more middleware.

Version 4 by hannes on 12. November 2009, 14:01

1Middleware is feature The idea of the Helma NG webapp framework that provides a simple interface middleware is to inject additional code between wrap the web server and [JSGI] application (or any middleware already wrapping the web applicationapplication) to run some pre- or post-request code. Middleware uses Since middleware exposes the same calling conventions as web app actions: a function that takes a Request object as argument and returns a Response objectJSGI interface to the outside world, it can be nested or "stacked" at will.
3Since Usually, JSGI middleware wraps the web comes as a function that takes a JSGI application (and any middlware stacked upon it)as argument, it is in full control of how the request is processedand returns a middleware function wrapping that app. For example, a simple middleware that adds logging to each request might be implemented as follows:
5* Inspect and modify the request object before processing it further    exports.Logger = function(app)
6* Decide not to pass the request on, returning its own response instead      return function(env)
7* Inspect and modify the response obtained from the application            log(env.SCRIPT_NAME + env.PATH_INFO);
8            return app(env);
9        };
10    }
11 
12The middleware that comes with Helma NG follows this pattern. Additionally, the Helma NG JSGI implementation offers a convenience feature to automatically instantiate and wrap middleware so you don't have to. All you need to do is export your middleware factory functions as an array called `middleware` in your `config` module. If your middleware factory function is called `middleware` or `handleRequest` it is even enough to just export the module name:
7Middleware 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  exports.middleware = 
8        'helma/middleware/gzip',
9        'helma/middleware/etag',
10        'helma/middleware/error',
11        'helma/middleware/notfound'
12    ];
9The <code>request</code> argument contains a <code>process</code> method that is used to pass above list shows some of the request on in the middleware chainthat comes with Helma NG. Thus, Have a middleware implementation that just passes on the request might look like this:at the [modules/helma/middlware][http://github.com/hns/helma-ng/tree/master/modules/helma/middleware] directory for more middleware.
11Of course, the great thing about JSGI middleware is that it's easy to write your own, exportsor use middleware from another package.
12    return req.process();
13  }
14
15Have a look at the *modules/helma/middlware|http://github.com/hns/helma-ng/tree/master/modules/helma/middleware* directory for the standard middleware currently shipping with Helma NG.

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

17Have 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.

Version 2 by hannes on 19. May 2009, 13:55

1Middleware is a feature of web connectors the Helma NG webapp framework that provides a simple interface to plug in inject additional code between the web server and the web app using a standard interfaceapplication. Another common term for middleware that is used in Middleware uses the Java Servlet API is "Filters"same calling conventions as web app actions: a function that takes a Request object as argument and returns a Response object.
2
3Since middleware wraps the web application (and any middlware stacked upon it), it is in full control of how the request is processed.
4
5* Inspect and modify the request object before processing it further
6* Decide not to pass the request on, returning its own response instead
7* Inspect and modify the response obtained from the application
8
9Middleware 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.
10
11The <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:
12
13  exports.handleRequest(req) {
14    return req.process();
15  }
16
17Have a look at the *modules/helma/middlware|https://dev.helma.org/trac/helma/browser/helma-ng/trunk/modules/helma/middleware* directory for the standard middleware currently shipping with Helma NG.
18

Version 1 by hannes on 20. February 2009, 20:07

1Middleware is a feature of web connectors to plug in additional code between the web server and the web app using a standard interface. Another common term for middleware that is used in the Java Servlet API is "Filters".