我想构建一个简单的sails应用程序,该应用程序利用签名cookie来存储会话数据,而不是任何类型的服务器端数据存储。到目前为止,我的阅读引导我调查Expresses' cookieSession,这可能是一个候选者 - 因为风帆声称它严重依赖于快速会话的实施。
这可能吗?是表达' cookieSession要走的路?这会在配置中的config / session.js中处理吗?如果是这样的话?我可能会利用哪些例子?
提前感谢我提供任何帮助!
修改
node-client-session是另一个看起来很有趣的选项。有谁知道这是否已经/可以在帆的背景下实施?
更新
以下答案似乎在正确的轨道上,我正在使用此方法在浏览器中显示一个cookie。但不幸的是,cookieSession创建的cookie对象似乎不适合对其进行的方法调用:
TypeError: Object #<Object> has no method 'resetMaxAge'
at ServerResponse.res.end (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/session.js:282:19)
at ServerResponse.res.send (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/response.js:152:8)
at fn (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/response.js:794:10)
at /Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/ejs-locals/index.js:134:7
at Object.exports.renderFile (/Users/huff/development/node/apps/authservice/node_modules/ejs/lib/ejs.js:317:3)
at SailsView.module.exports [as engine] (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/ejs-locals/index.js:85:7)
at SailsView.View.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/view.js:76:8)
at Function.app.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/application.js:506:10)
at ServerResponse.res.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/response.js:798:7)
at /Users/huff/development/node/apps/authservice/config/404.js:35:9
at /Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/ejs-locals/index.js:134:7
at Object.exports.renderFile (/Users/huff/development/node/apps/authservice/node_modules/ejs/lib/ejs.js:317:3)
at SailsView.module.exports [as engine] (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/ejs-locals/index.js:85:7)
at SailsView.View.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/view.js:76:8)
at Function.app.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/application.js:506:10)
at ServerResponse.res.render (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/lib/response.js:798:7)
at Object.pageNotFound [as 404] (/Users/huff/development/node/apps/authservice/config/404.js:30:7)
at Object.handle (/Users/huff/development/node/apps/authservice/node_modules/sails/lib/express/index.js:198:21)
at next (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.favicon [as handle] (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/favicon.js:77:7)
at next (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at resume (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7)
at SendStream.error (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37)
at SendStream.EventEmitter.emit (events.js:95:17)
at SendStream.error (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/send/lib/send.js:147:51)
at SendStream.onStatError (/Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/send/lib/send.js:248:48)
at /Users/huff/development/node/apps/authservice/node_modules/sails/node_modules/express/node_modules/send/lib/send.js:320:26
at Object.oncomplete (fs.js:107:15)
这些问题始终存在。如果我发表评论&#39; resetMaxAge&#39;在expres代码中,我通过调用save方法获得相同的东西。关于如何通过这个快速功能让帆更好玩的任何想法?
答案 0 :(得分:2)
您可以通过创建新的配置文件轻松访问基础快速引擎。
//./config/express.js
module.exports.express = {
customMiddleware: function (app) {
app.use(connect.cookieParser());
app.use(connect.cookieSession({ secret: 'tobo!', cookie: { maxAge: 60 * 60 * 1000 }}));
//or even use passportjs.
app.use(passport.initialize());
app.use(passport.session());
}
}