visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

req.session undefined #52

Open panosru opened 12 years ago

panosru commented 12 years ago

I noticed that req.session is undefined for resources but it works fine for manually added routes using app.get method

{ lastAccess: 1329521660742,
  cookie: 
   { path: '/',
     httpOnly: true,
     _expires: Sat, 18 Feb 2012 03:34:20 GMT,
     originalMaxAge: 14400000 },
  _csrf: 'B91I4oOdFYhs3h9PNdBsJagE' }

  GET /404
  response time: 20ms
  memory rss: 148.00kb
  memory vsize: NaNgb
  heap before: 29.63mb / 107.27mb
  heap after: 30.42mb / 107.30mb

undefined

  GET /
  response time: 9ms
  memory rss: 0b
  memory vsize: NaNgb
  heap before: 18.28mb / 52.08mb
  heap after: 18.85mb / 52.08mb

/ is set through app.resource and /404 is set through app.get

panosru commented 12 years ago

ok, I got it wrong, req.session is undefined with app.get too, in the above example I didn't had /404 route set as I though I had app.use with a method as a param that handle's not found routes... strange that req.session is undefined... it used to work :S

panosru commented 12 years ago

it seems that if I setup resources before app.configure they work but they don't have req.session object (which is normal since the session is not yet initialized) if I setup resources after app.configure then I'm getting error when I try to load a url:

Error: Can't render headers after they are sent to the client.
    at ServerResponse.<anonymous> (http.js:562:11)
    at ServerResponse._renderHeaders (/Volumes/Web/debian6/users/rnd/domains/design.rnd/public_html/app-ui/node_modules/express/node_modules/connect/lib/patch.js:76:25)
    at ServerResponse.writeHead (http.js:848:20)
    at ServerResponse._implicitHeader (http.js:805:8)
    at ServerResponse.write (/Volumes/Web/debian6/users/rnd/domains/design.rnd/public_html/app-ui/node_modules/gzippo/lib/compress.js:80:34)
    at ServerResponse.end (/Volumes/Web/debian6/users/rnd/domains/design.rnd/public_html/app-ui/node_modules/gzippo/lib/compress.js:87:23)
    at /Volumes/Web/debian6/users/rnd/domains/design.rnd/public_html/app-ui/node_modules/i18next/lib/i18next.js:78:21
    at [object Object].<anonymous> (fs.js:115:5)
    at [object Object].emit (events.js:64:17)
    at afterRead (fs.js:1111:12)
panosru commented 12 years ago

From what I understood so far from the debugging I did is that if you use app.enable('strict routing') with express-resource you'll have some un-expected behavior thus I disabled it (although I would prefer to have it enabled).

Regarding the Can't render headers after they are sent to the client. error message it was produced because of app.use(Gzippo.compress()) from gzippo module, I had to remove it for now and use the plain app.static() method but I would like to send gziped content...

//cc @tomgallacher