nodejs sessionStore:api?

时间:2017-01-19 22:49:45

标签: javascript node.js

在哪里可以找到有关req.sessionStore的api信息?

我正在查看申请的图书馆:

Object.defineProperty(this, 'req', { value: req });
 this.req.sessionStore.set(this.id, this, fn || function(){});

https://github.com/btd/connect-session/blob/master/lib/session/session.js#L24

但是很难找到这样的api 欢迎提供有关request.sessionStore的替代文档。

1 个答案:

答案 0 :(得分:0)

简答所有商店方法都可以在这里获得: https://github.com/expressjs/session#session-store-implementation

长答案 调试此

需要3个步骤

首先req.sessionstore来自哪里?

https://github.com/btd/connect-session/blob/master/lib/session.js#L78

// expose store
req.sessionStore = store;

其次,什么是商店,它可以在创建会话时通过选项传递,或者它将从MemoryStore中选择

https://github.com/btd/connect-session/blob/master/lib/session.js#L46

store = options.store || new MemoryStore

第三,MemoryStore是我们拥有所有setter方法的地方

https://github.com/btd/connect-session/blob/master/lib/session/memory.js#L67

MemoryStore.prototype.set 

由于connect和express共享类似的中间件,对于其他兼容的会话库而不是默认的MemoryStore,你可以参考

https://github.com/expressjs/session#compatible-session-stores