I'm using connect
, passport
and session.socket.io
modules in my application. On the connection
event of the session.socket.io I receive an error: could not look up session by key: connect.sid
The situation is like this one
My server side code is:
var mod_http = require('http');
var mod_connect = require('../../lib/node_modules/connect');
var mod_connectRoute = require('../../lib/node_modules/connect-route');
var mod_ejs = require('../../lib/node_modules/ejs');
var mod_SessionSockets = require('../../lib/node_modules/session.socket.io');
var mod_passport = require('../../lib/node_modules/passport'), LocalStrategy = require('../../lib/node_modules/passport-local').Strategy;
var mod_fs = require('fs');
var app = mod_connect();
var cookieParser = mod_connect.cookieParser('your secret sauce'),
sessionStore = new mod_connect.middleware.session.MemoryStore();
app.use(mod_connect.static(folder));
// Configure the app connection
app.use(cookieParser);
app.use(mod_connect.bodyParser());
app.use(mod_connect.session({ secret: 'logged' }));
app.use(mod_passport.initialize());
app.use(mod_passport.session());
app.use(mod_connectRoute(function (router) {
router.get('/', function (req, res, next) {
...
}
}
var server = mod_http.createServer(app),
io = require('../../lib/node_modules/socket.io').listen(server);
// Limit the messages shown.
io.set('log level', 2);
// Create a session.
var sessionSockets = new mod_SessionSockets(io, sessionStore, cookieParser);
// Fire when a browser install a connection. A page refresh closes the connection and creates new one.
sessionSockets.on('connection', function (err, socket, session) {
console.log(err);
console.log(sessionStore);
console.log('Hello!');
});
server.listen(4000);
Client code:
<!DOCTYPE html> <!-- HTML 5 -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="/style.css">
<script src="/jquery-1.9.1.js"></script>
<meta charset="utf-8">
<title> Test </title>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
socket = io.connect('http://'+location.host);
</script>
<script src="/functions.js"></script>
...
</body>
</html>
When I open the localhost:4000
page I can see the following output on the node.js console:
[Error: could not look up session by key: connect.sid]
{ sessions: {} }
Hello!
PS: due to my low reputation I can't add a new tag for the discussion, but I think that this discussion will need the tag session.socket.io, will be appreciated if someone can add it, thanks
I'm using connect
, passport
and session.socket.io
modules in my application. On the connection
event of the session.socket.io I receive an error: could not look up session by key: connect.sid
The situation is like this one
My server side code is:
var mod_http = require('http');
var mod_connect = require('../../lib/node_modules/connect');
var mod_connectRoute = require('../../lib/node_modules/connect-route');
var mod_ejs = require('../../lib/node_modules/ejs');
var mod_SessionSockets = require('../../lib/node_modules/session.socket.io');
var mod_passport = require('../../lib/node_modules/passport'), LocalStrategy = require('../../lib/node_modules/passport-local').Strategy;
var mod_fs = require('fs');
var app = mod_connect();
var cookieParser = mod_connect.cookieParser('your secret sauce'),
sessionStore = new mod_connect.middleware.session.MemoryStore();
app.use(mod_connect.static(folder));
// Configure the app connection
app.use(cookieParser);
app.use(mod_connect.bodyParser());
app.use(mod_connect.session({ secret: 'logged' }));
app.use(mod_passport.initialize());
app.use(mod_passport.session());
app.use(mod_connectRoute(function (router) {
router.get('/', function (req, res, next) {
...
}
}
var server = mod_http.createServer(app),
io = require('../../lib/node_modules/socket.io').listen(server);
// Limit the messages shown.
io.set('log level', 2);
// Create a session.
var sessionSockets = new mod_SessionSockets(io, sessionStore, cookieParser);
// Fire when a browser install a connection. A page refresh closes the connection and creates new one.
sessionSockets.on('connection', function (err, socket, session) {
console.log(err);
console.log(sessionStore);
console.log('Hello!');
});
server.listen(4000);
Client code:
<!DOCTYPE html> <!-- HTML 5 -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="/style.css">
<script src="/jquery-1.9.1.js"></script>
<meta charset="utf-8">
<title> Test </title>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
socket = io.connect('http://'+location.host);
</script>
<script src="/functions.js"></script>
...
</body>
</html>
When I open the localhost:4000
page I can see the following output on the node.js console:
[Error: could not look up session by key: connect.sid]
{ sessions: {} }
Hello!
PS: due to my low reputation I can't add a new tag for the discussion, but I think that this discussion will need the tag session.socket.io, will be appreciated if someone can add it, thanks
0 commentaires:
Enregistrer un commentaire