sails.js - Empty response on long running query SailsJS -


i'm running sailsjs on raspberry pi , working when execute sails.models.nameofmodel.count() when attempt respond result end getting empty response.

getlistcount: function(req,res)     {             var mainsource = req.param("source");              if(mainsource)             {                 sails.models.gatherer.find({source: mainsource}).exec(                         function(error, found)                         {                                 if(error)                                 {                                         return res.servererror("error in call");                                 }                                 else                                 {                                         sails.log("number found "+found.length);                                         return res.ok({count: found.length});                                 }                         }                    );         }         else         {                 return res.ok("error in parameter");         }    }, 

i able see in logs number found (73689). when responding still empty response. using default stock ok.js file, did stick in additional logging try debug , make sure going through correct paths. able confirm ok.js going through path

if (req.wantsjson) {     return res.jsonx(data); } 

i tried adding .populate() call before .exec(), res.status(200) before sent out res.send() instead of res.ok(). i've updated sails 11.5 , still getting same empty response. i've used sails.models.gatherer.count() call same result.

you can try add logging beginning of method capture value of mainsource. not believe need use explicit return response object calls.

if looks normal there, try eliminate model's find method , evaluate request parameter , return simple response:

getlistcount: function(req, res) {     var mainsource = req.param("source");     sails.log("value of mainsource:" + mainsource);      if (mainsource) {       res.send("hello!");     } else {       res.badrequest("sorry, missing source.");      } } 

if not work, model data may not matching on criteria providing , problem may lie there; in case, response null. mentioned see resulting count of query within log statement. if res.badrequest null, may have problem version of express installed within sailsjs. mention have 11.5 of sailsjs. assume mean 0.11.5.

this found in package.json of 0.11.5

   "express": "^3.21.0", 

check possible bugs within github issues sailsjs regarding express , response object handling , above version of express.

it may worthwhile perform clean install using latest sailsjs version (0.12.0) , see if fixes issue.

another issue may in how handling response. in case .exec should execute query (i.e. synchronous call) , return response when complete. there should no asynchronous processing there.

if can show code consuming response, helpful. assuming there view showing response via ajax or kind of form post being performed. if seeing null response, perhaps problem lies in view layer rather controller/model.

if experiencing true timeout error via http though query returns result in time, may need consider using async processing sailjs. take @ post on using promise instead.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -