use*_*947 6 javascript node.js express express-session
我有一个使用 express-session 的 NodeJS Express 应用程序。只要支持会话 cookie,这很有效。
不幸的是,它还需要与不支持任何类型 cookie 的 PhoneGap 应用程序一起使用。
我想知道:是否可以使用 sessionID 获得快速会话并访问该会话中的数据?
我想我可以为 PhoneGap 应用程序发送的每个请求附加 sessionID 作为查询字符串参数,如下所示:
https://endpoint.com/dostuff?sessionID=whatever
但我不知道如何告诉 express 检索会话。
您当然可以创建一个快速路由/中间件来欺骗express-session传入请求包含会话 cookie。在会话中间件之前放置类似的内容:
app.use(function getSessionViaQuerystring(req, res, next) {
var sessionId = req.query.sessionId;
if (!sessionId) return res.send(401); // Or whatever
// Trick the session middleware that you have the cookie;
// Make sure you configure the cookie name, and set 'secure' to false
// in https://github.com/expressjs/session#cookie-options
req.cookies['connect.sid'] = req.query.sessionId;
next();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4819 次 |
| 最近记录: |