I want get response, to save cookie.. I used express on node.js
app.post('/', function (req, res) {
res.setHeader("Set-Cookie", ["dok=javascript"]);
})
I want to do outside of app.post - real time used socket.io
for example:
socket.on('Login-clicked', function(data) {
if(data == ok) {
res.setHeader("Set-Cookie", ["dok=javascript"]);
}
});
How can i do?
I think what you are trying to do here is access res in socket.on('Login-clicked') event.To do that first make res global.
global.res={};
app.post('/', function (req, res) {
global.res=res;
});
socket.on('Login-clicked', function(data) {
if(data == ok) {
global.res.setHeader("Set-Cookie", ["dok=javascript"]);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.