Reputation: 66
I am new to node and using stormpath for custom data, my server code retrieves the accounts in a group with the custom data for each. It should send data to client.. However I am getting error.. Any kind of help will be helpful, thanks.
Error : "Can't set headers after they are sent."
app.post('/profile/cards', bodyParser.json(),ExpressStormpath.loginRequired,function(req, res) {
var href="https://api.stormpath.com/v1/groups/2D48mI3C9uBFJAFW3pp7Kv";
client.getGroup(href,function(err,group){
group.getAccounts(function(err,accounts){
accounts.each(function(account,cb){
account.getCustomData(function(err,CustomData){
res.send(CustomData);
});
cb();
},function(err){
console.log('Finished iterating over accounts');
});
});
});
});
Upvotes: 2
Views: 50
Reputation: 33824
Your code isn't working because you're iterating over Groups in Stormpath and attempting to return a web page to the user (res.send
) on each call which is NOT allowed.
You can only call res.send()
a single time per route.
Upvotes: 1