I'm using sailsjs and I'm trying to return the response with JSON content type. Don't know why
Application.getEmailDuplicateCheck(options, function(error, result) {
console.log('Email duplicate check error', error);
console.log('Email duplicate check result', result);
if (error) {
return res.serverError(error);
}
if (result) {
return res.ok(result); /*** THIS IS LINE 180 ***/
}
});
And not sure why the it always says that "Can't set the headers after they are sent" because I put all the response with return;
> Error: Can't set headers after they are sent.
> at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
> at ServerResponse.res.setHeader (/home/apps/cat/api/node_modules/express/node_modules/connect/lib/patch.js:134:22)
> at ServerResponse.res.set.res.header (/home/apps/cat/api/node_modules/express/lib/response.js:595:10)
> at ServerResponse.res.send (/home/apps/cat/api/node_modules/express/lib/response.js:151:12)
> at ServerResponse.res.json (/home/apps/cat/api/node_modules/express/lib/response.js:237:15)
> at ServerResponse.res.send (/home/apps/cat/api/node_modules/express/lib/response.js:139:21)
> at /home/apps/cat/api/api/controllers/DuplicateCheckController.js:180:16