connect.session doesn't work for connect > 2.3.5 #35

Closed
KenjiTakahashi opened this Issue Jul 13, 2012 · 6 comments

Projects

None yet

5 participants

@KenjiTakahashi

It dies with

/home/kenji/nodejs/union/node_modules/connect/lib/middleware/session.js:213
    if (0 != req.originalUrl.indexOf(cookie.path || '/')) return next();
                             ^
TypeError: Cannot call method 'indexOf' of undefined
    at Array.session [as 4] (/home/kenji/nodejs/union/node_modules/connect/lib/middleware/session.js:213:30)
    at dispatch (/home/kenji/nodejs/union/node_modules/union/lib/routing-stream.js:110:21)
    at g (events.js:185:14)
    at EventEmitter.emit (events.js:85:17)
    at RoutingStream.route (/home/kenji/nodejs/union/node_modules/union/lib/routing-stream.js:114:23)
    at Array.cookieParser [as 3] (/home/kenji/nodejs/union/node_modules/connect/lib/middleware/cookieParser.js:60:5)
    at dispatch (/home/kenji/nodejs/union/node_modules/union/lib/routing-stream.js:110:21)
    at g (events.js:185:14)
    at EventEmitter.emit (events.js:85:17)
    at RoutingStream.route (/home/kenji/nodejs/union/node_modules/union/lib/routing-stream.js:114:23)

Minimal example to reproduce:

var connect = require('connect')
  , union = require('union');

var server = union.createServer({
  buffer: false,
  before: [
    connect.cookieParser('my secret here'),
    connect.session()
  ]
}).listen(3000);
Contributor

Please use this temporary hack

var connect = require('connect')
  , union = require('union');

var server = union.createServer({
  buffer: false,
  before: [
    function (req, res) {
      req.originalUrl = req.url;
      res.emit('next');
    },
    connect.cookieParser('my secret here'),
    connect.session()
  ]
}).listen(3000);

I switched back to connect 2.3.5 in the meanwhile, no big deal for me.
Just wanted you to know that there's something wrong.

Owner

I've seen this as well. It's annoying but we should probably set .originalUrl for forwards compatibility. @pksunkara can you investigate why they made the change in connect and make the corresponding change in union?

I'll look for a PR from you.

Contributor

Sure, connect ~2.3.5 has lost compatibility with union in a lot of cases. I have been investigating this since 2 days.

Owner
3rd-Eden commented Aug 3, 2012

I just bumped in to this issue my self as well. It seems to me that it's really easy to fix this in union.

cscade commented Aug 15, 2012

Just ran into this as well. Using the workaround posted above for the moment, thanks.

@pksunkara pksunkara closed this in f8d6fec Nov 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment