The code from the previous post indeed invokes the x-ray function on the server side but doesn't return the result to the client.
Using async/wait and promises (ES7) you can return the result from the server to the client:
method.js (server):
import { Meteor } from 'meteor/meteor';
import Xray from 'x-ray';
Meteor.methods({
async 'scrape.test'() {
let x = Xray(),
scraper;
function scrap() {
return new Promise((r, e) => {
x('http://google.com', 'title')(function(err, title) {
if (err) e(err);
if (title) r(title);
});
});
}
try {
return await scrap();
} catch (error) {
throw new Meteor.Error('500', error);
}
}
});
client.js:
Meteor.call('scrape.test', (error, result) => {
if (error) console.log('error', error);
console.log('result', result);
});
Cheers