How to work with Picker.route correctly


#1

Hello, I have this code on my server:

Picker.route('/api', function(params, req, res, next) {
    Meteor.call('checkTransaction', params);
    var response = "OK" + params.query['InvId'];
    res.end(response);
});

But it is problem when third-party payment service tryes to send get request to this address. I should to call one function and send response. When I’m calling function before sending response, this payment service always gets error like “broken connection” or something. So, problem is how to do both things: call function and send response?


#2

It could be the meteor method crashing which could respond something. Try commenting that out and just using:

Picker.route('/api', function(params, req, res, next) {
    //Meteor.call('checkTransaction', params);
    //var response = "OK" + params.query['InvId'];
    res.end("OK Test");
});

You can test this with curl in the the terminal:
curl http://localhost:3000/api

then once that works try:

Picker.route('/api', function(params, req, res, next) {
    //Meteor.call('checkTransaction', params);
   console.log("Params: ", params.query['Invld']) 
   var response = "OK" + params.query['InvId'];
   res.end(response);
});

And once that works add the method. Also you should wrap everything in a try catch to prevent leaking data (and return a 500 error code with res).