flatiron/union

connect.session doesn't work for connect > 2.3.5

KenjiTakahashi opened this issue · 6 comments

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);

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.

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.

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

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.

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