On Saturday, March 24, 2012 4:05:15 AM UTC+1, Tim Caswell wrote:
>
> That's actually not a bad model. The connect middleware system I designed
> works like that. Each middleware is a standalone module. It may depend on
> some other modules for functionality (the static file server module depends
> on the mime database module). But as far as runtime configuration and
> app-level data, I pass it in at the app level. Each connect plugin looks
> like.
>
> // A static library that all instances of this middleware can share
> var getMime = require('mime').getMime;
>
> // Factory function to create an instance of this middleware.
> module.exports = function setup(config, args, go, here) {
> // This closure level contains any instance level state and logic.
> It's executed
> // once at server startup for each instance of this middleware.
>
> // Return the middleware object (in connect it's a request handler
> function)
> return function handleRequest(req, res, next) {
> // This code is executed on every http request.
> };
> };
>
> You don't have to use the factory pattern to create your objects, but what
> I want to showcase is that you can separate your logic and state into
> different levels. There can be state shared by all instances of this
> module, there is state per instance (this usually has the business logic in
> it.). More layers can be nested in deeper if it's natural to your app. If
> the nesting gets too deep, then start fresh in a new file or a new function
> and remember to pass in all the needed state in the new layer.
>
Could you please show me the code which would use this module? I'm having
little bit of a hard time changing this to my context of authentication to
understand how I would use it.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en