a simple example: https://gist.github.com/3337459
在 2012年8月24日星期五UTC+8下午10时47分21秒,0x80写道:
>
> I'm trying to use express with socket.io and make them share sessions. I
> have found examples online and in my "Node up and running" book but somehow
> I can't get it to work. I must be doing something stupid.
>
> The problem is that in the authorization function of the socket
> sessionStore.get() always seems to return undefined for both error and
> session object. Here's my authorize function:
>
> sio.configure(function(){
> sio.set('authorization', function(data, accept){
>
> if(data.headers.cookie){
> // parseCookie not available anymore
> // var cookies = utils.parseCookie(data.headers.cookie);
> var cookies = cookie.parse(data.headers.cookie);
>
> data.sessionID = cookies['express.sid'];
> console.log("sessionID", data.sessionID);
>
> data.sessionStore = sessionStore;
> console.log("store", util.inspect(sessionStore, true, null));
>
> sessionStore.get(data.sessionID, function(err, session) {
> if( err || !session) {
> console.log("ERROR", err);
> console.log("session:", util.inspect(session));
> return accept("Invalid session", false);
> }
> console.log("creating session data");
> data.session = new Session(data, session);
>
> accept(null, true);
> });
> }else{
> return accept("No cookie transmitted.", false);
> }
> });
> });
>
> And this is the output:
>
> sessionID
> s:fTZNjPuFIIr5sZvXLCwfR/EQ.6r41SUae3OAQokT58uypmCnajApCyFEfDaWakmlTfYY
> store { generate:
> { [Function]
> [prototype]: { [constructor]: [Circular] },
> [name]: '',
> [arguments]: null,
> [length]: 1,
> [caller]: null },
> sessions: { 'fTZNjPuFIIr5sZvXLCwfR/EQ':
> '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"}}'
>
> } }
> ERROR undefined
> session: undefined
> debug - authorized
> warn - handshake error Invalid session
>
>
> As I see it, the session store clearly holds a session with an id similar
> to the session id (only up until the "."?), so I don't understand why the
> get() function returns nothing. Where is that function defined anyway and
> why doesn't it show up in the util.inspect printout?
>
> This is what I'm using:
>
> ├─┬ [email protected]
> │ ├── [email protected]
> │ ├─┬ [email protected]
> │ │ ├── [email protected]
> │ │ ├── [email protected]
> │ │ ├── [email protected]
> │ │ └── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ ├── [email protected]
> │ └─┬ [email protected]
> │ └── [email protected]
>
--
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