Cookie都搞不定了,writeHead or render?
我用了ejs模版,所以需要render. res.render(‘index’, {title: ‘Express’}); res.writeHead(200,{ ‘Set-Cookie’:‘myCookie=“type=ninja”, “language=javascript”;path="/";Expires=’+timeObj+’;httpOnly=true’ });
不管先执行哪个都报错:Error: Can’t set headers after they are sent. 怎么办?writeHead没有回调吧?
1 回复
response.setHeader(
'Set-Cookie', serialize(key, val, {path: "/", expires: exp})
);
好吧 ,还得多看书