MeteorJS Meteor Methods call from server to server -


i understand meteor methods let client server call, what's best approach call function or method meteor method, i.e. server server call.

right if regular js function call works if js file in lib folder. need in server folder.

here code

i have topics collection sits in collection folder , has following

i have following collection

meteor.methods({     topicpost: function(topicattributes) {         var user = meteor.user(),             topicwithsametitle = topics.findone({title: topicattributes.title});          // ensure user logged in         if (!user)             throw new meteor.error(401, "you need login add new topic");          meteor.call('checkuser'); } }); 

i have following method sits in server folder

meteor.methods({     checkuser: function () {         alert('aaaa');     } }); 

this works, it's not great solution. method handling have all of functions outside meteor.methods, , relay proper functions when necessary.

// client meteor.call('foo'); 

and:

// server meteor.methods({     foo: function() {         foo();     } });  foo = function() {     foo = bar; }; 

the advantage foo fn can called anywhere on server without meteor.call. meanwhile, meteor.methods exposes absolutely necessary client.

[edit] there is ambiguity 'foo' you're talking about; server knows mean 1 outside methods call. if you're feeling confused, can rename 1 or other. advantage there minimal refactoring involved.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -