javascript - Can't get cookies to send with request in Express 4 -
here's initial config:
var session = require('express-session'); var cookieparser = require('cookie-parser'); app.use(session({ saveuninitialized: true, resave: false, genid: function(req) { return services.misc.generateuuid() }, secret: secret.tostring() })); app.use(cookieparser(secret));
then in controller (it's routed through dead simple router controller, renders appropriate actions based on rails-like naming convention) i'll this:
var testcontroller = { noaction: function(req, res) { var locals = { billy: 'the goat' } console.log('req session'.red, req.session); res.cookie('test_cookie', 'wu tang clan'); this.services.render.view(req, res, this, 200, locals); } module.exports = testcontroller;
note this.services.render.view
service don't have write res.render('./app/controllers' + controller + '/' + action)
note res.cookie line in controller (docs on express.js). that's official docs , in fact, it's set in browser:
however, line above res.cookie log , imagine we'd have test_cookie
in it, but:
all standard blank cookie every time, though it's set browser-side , supposedly sending.
my question is: how set , receive cookies in express 4?
your code seems ok, dsp_099 said, nodemon. express-session saves data in-memory, when restart server (with nodemon automatically) memory data reseted.
i wanna persist session data if node restarted, may suggest use redis-session (redis database)
Comments
Post a Comment