Using node.js client-sessions without express

三世轮回 提交于 2019-12-11 12:28:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!