Reputation: 405
I have two node servers where node server2(port 3001) receives requests from node server1(running on port 3000).
When i bind data in server1 and make post call to server2 , server2 always caches the old data maintained in previous call.
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 comfiguaraton -
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'));
});
Method that make rest API call to server2 exports.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 Method that receives the request data:
app.post('/docleansematch',function(req,res){
log.info('Cached Number of records - '+ req.body.records.length);
res.json({status:3});
}
Upvotes: 1
Views: 1568
Reputation: 405
On my further Analysis , Server1 maintains a cache while sending the values in request form submission..
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);
});
};
Server1 -> form : req.body caches the values sent in post request and on the subsequest post call has the old data appended in the form.. so that server2 receives all with the appended data.
Do you know how to clear cache in the request module of nodejs ??
Upvotes: 2