我正在用Android编写应用程序,但我不知道如何仅将响应发送给在Express-Session中使用特殊ID生成会话的设备。例如,我有3部手机,并同时单击池中的差异数据登录按钮,所有3台设备捕获了相同的对象,而不是3个不同的目的地(来自express的第一个响应对象被3台设备捕获,其余2个对象被忽略,i想要向每个对象发送对象)。
....
var express = require('express');
var session = require('express-session');
var crypto = require('crypto');
var uuid = require('node-uuid');
var app = express();
app.use(session({
secret: 'DFGDFG',
resave: false,
saveUninitialized:false,
genid:function(req){
return crypto.createHash('sha256').update(uuid.v1()).update(crypto.randomBytes(256)).digest("hex");
},
}));
app.post('/login', (request,response)=> {
var post_data = request.body;
request.session.user = post_data.user;
request.session.password = post_data.password;
if(err){
console.log("error");
}
else{
var db= client.db('test');
db.collection('object').findOne({'user':request.session.user}, function(error,user){
if(user.password == request.session.password){
request.session.amount = user.amount; // if password was correct, sending amount account
console.log('Success');
res.send(request.session.amount);
}
else{
console.log('Password invalid');
}
}
});