On Sun, Sep 8, 2013 at 3:38 PM, Adam Ahmed <[email protected]> wrote:

> Hi all,
>
> I'm working on a website that does all the basic stuff: permissions,
> authentication, CRUD on objects, etc. One thing that has been a bit hard is
> passing around the context of a request - the session information, who the
> user is, etc.
>
> …
>
> I was wondering if anyone had a good solution to this, or if my best bet
> is to continue manually passing that info around.
>

There's been some discussion of this recently:

https://groups.google.com/d/msg/nodejs/cu9kE4QDhjo/0Q6JHIm-gTEJ

The tl;dr is that Tim Caswell (creationix) and I have written a module (
https://npmjs.org/package/continuation-local-storage) that does pretty much
exactly what you describe, with the exception that it's not based on
thread-local contexts (because JS code in Node will always be
single-threaded) but local to a particular set of synchronous and
asynchronous function calls. It works on top of an API added to Node core,
which Trevor Norris is implementing on top of Node right now (
https://github.com/joyent/node/pull/6011) and which creationix and I have
written as a polyfill (https://npmjs.org/package/async-listener) for
versions of Node that don't have it in core (which, at the moment, is all
of them).

You can use domains, or in a pinch put whatever properties you want carried
through directly onto req and res (which is the approach used by most
Connect middleware), but things get complicated fast when you want
asynchronously scoped local variables *and* domain-style error handling.
The asyncListener polyfill is unavoidably expensive right now (although I
haven't had the opportunity yet to measure *how* expensive), but the API is
clean and it works. Check out CLS and let me know if there are bits of it
that are confusing or unusable for you.

F

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to