What works easily in python using requests module, doesn’t work in my meteor app using http package.
j@j-desktop:~/_Github-Projects/inventory_synchronize$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('http://jsonplaceholder.typicode.com/posts').text
in my meteor app, inside the file inventory_synchronize/server/main.js, I have
The exception I’m getting is Exception while invoking method 'insertInvFromEbayJson' ReferenceError: reponse is not defined
I understand that I’m using the function get, synchronously, so the execution should block until the request returns a response there which is fine in this context and my testing.
I think what might be happening is that you are seeing the result of this code being run on the client. You’ll need to move the method definition to server only code.
Thanks, you helped fix it. I actually don’t need to have the method return anything so I can just update the db from within the server sided method.
updated server/main.js file contents:
Meteor.methods({
insertInvFromEbayJson(filePath) {
if (canViewInventory(this.userId)) {
console.log('file', filePath);
HTTP.get(
url=filePath,
asyncCallback=(err, response) => {
if (err) throw err;
console.log(response.content);
});
} else {
console.warn('you do not have permission to insert into this db');
}
}
});
imports/ui/App.js
// in some file upload callback method
Meteor.call('insertInvFromEbayJson', downloadUrl));