SHARE
TWEET

Untitled

a guest Jun 16th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.post('/api/botjobs.json', function(req, res) {
  2.     // console.log(req.body)
  3.     data = req.body;
  4.     var temp = {};
  5.     temp.radar = data.radar;
  6.     temp.request = data.request;
  7.     if(temp.request == 'cloneradar'){
  8.         temp['params.clonetype'] = data.params.clonetype;
  9.     }
  10.     now = new Date();
  11.     data["updated"] = now;      
  12.     // console.log('DATA:')
  13.     // console.log(data)
  14.     // console.log('TEMP:')
  15.     // console.log(temp)
  16.     botjobs.findOne(temp, {}, { sort:{'_id': -1}}, function(err, findstat){
  17.         // console.log(findstat)
  18.         // console.log(err)
  19.         // console.log("inside botjobs findOne");
  20.         if(findstat != null){
  21.             // console.log('updating entry')
  22.             //console.log(findstat);
  23.             data['numupdated'] = findstat['numupdated']+1;
  24.             // console.log(data);
  25.             botjobs.update({'_id':findstat['_id']},data,{ upsert : true, multi: true },function(err,stat){
  26.                 if (err)
  27.                     res.send(err);
  28.  
  29.                 res.json(stat); // return in JSON format
  30.             });
  31.  
  32.         }
  33.         else{
  34.             // console.log('creating new entry')
  35.             data["created"] = now;
  36.             data['numupdated'] = 0;
  37.             botjobs.create(data,function(err, stat) {
  38.                 // console.log(stat);
  39.                 // if there is an error retrieving, send the error. nothing after res.send(err) will execute
  40.                 if (err)
  41.                     res.send(err);
  42.  
  43.                 res.json(stat); // return in JSON format. —> line 413 in route.js
  44.             });
  45.         }
  46.  
  47.     });
  48.  
  49. });
  50.      
  51. Error: Can't set headers after they are sent.
  52.     at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:350:11)
  53.     at ServerResponse.res.setHeader (/app/node_modules/express/node_modules/connect/lib/patch.js:134:22)
  54.     at ServerResponse.res.set.res.header (/app/node_modules/express/lib/response.js:595:10)
  55.     at ServerResponse.res.send (/app/node_modules/express/lib/response.js:151:12)
  56.     at ServerResponse.res.json (/app/node_modules/express/lib/response.js:237:15)
  57.     at /app/app/routes.js:413:10
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top