【发布时间】:2014-08-01 03:40:40
【问题描述】:
我有两个节点服务器,其中节点服务器 2(端口 3001)接收来自节点服务器 1(在端口 3000 上运行)的请求。
当我在 server1 中绑定数据并对 server2 进行 post 调用时,server2 总是缓存在先前调用中维护的旧数据。
For ex : Old Post data is { emailid : 'xxxx',
name : 'XXXX',
records : [0,1,2,3,4]
}
If Next POST data from server1 is { emailid : 'xxxx',
name : 'XXXX',
records : [5,6]
}
Then Server2 recieves these data as { emailid : 'xxxx',
name : 'XXXX',
records : [5,6,2,3,4]
}
I dont want the old records 2,3,4 in req.body.records array .. but it is cached.
Could you please help me how to remove the caching of the old data in request body container.
Please look at my server1 code where i make REST calls using node request module:
Server1 配置 -
app.configure(function() {
// The cookieParser should be above session
app.use(express.cookieParser());
app.use(express.session({secret:'ayer'}));
// Request body parsing middleware should be above methodOverride
app.use(express.urlencoded());
app.use(express.json());
// app.use(expressValidator());
app.use(express.methodOverride());
// Routes should be at the last
app.use(app.router);
// Setting the fav icon and static folder
//app.use(express.favicon());
app.use(express.favicon(__dirname + '/public/favicon.ico'));
//app.use('/', express.static(config.root + '/public'));
});
对 server2 进行 REST API 调用的方法 export.docleansematch = function(req,res,sessionStore){
/*setting up user verification request options*/
var Options = {
uri: 'http:localhost:3001/docleansematch',
method: 'POST',
json:true,
proxy: config.app.proxy, // calling to internal server
headers: {'Content-Type':'application/x-www-form-urlencoded'
},
form : req.body
};
request.post(Options,function(err,extResponse,extResponseBody)
{
var data = {};
if(err)
{
log.error('Error in App layer : ',err);
data.status = 2;
}
else
{
data.status = extResponseBody.status;
}
res.jsonp(data);
});
};
Server2 接收请求数据的方法:
app.post('/docleansematch',function(req,res){
log.info('Cached Number of records - '+ req.body.records.length);
res.json({status:3});
}
【问题讨论】:
-
请发一个真实的测试用例结果。在您的示例中,第二个回复中没有 0,1。它不加起来。还发布一个可重现的示例。我们可以在我们的机器上测试的东西。
标签: node.js express mean-stack