问题
I'm trying to get client-sessions to work without using express but I'm not sure if I'm porting the example correctly.
var sessionOptions = { cookieName: 'mySession',
secret: 'blargadeeblargblarg',
duration: 24 * 60 * 60 * 1000,
activeDuration: 1000 * 60 * 5 };
var session = new SESSION(request, response, {}, sessionOptions);
When I run this client-sessions complains
cannot set up sessions without a secret or encryptionKey/signatureKey pair
Does client-sessions need express to work?
回答1:
From https://github.com/mozilla/node-client-sessions:
client-sessions is connect middleware
So while it might not need express
, it needs connect
to work as per the docs.
The specific error though, is because you aren't using the library correctly. You need to configure a session before using it.
var sessions = require("client-sessions");
var session = sessions({
cookieName: 'mySession',
secret: 'blargadeeblargblarg',
duration: 24 * 60 * 60 * 1000,
activeDuration: 1000 * 60 * 5
});
// then inside route handler..
session(req, res, function(){ console.log('done!'); });
来源:https://stackoverflow.com/questions/29576768/using-node-js-client-sessions-without-express