ValidatedMethod and Client side functionality

Hi All,

I tried to move some of my Methods to the ValidatedMethod format. The file which defines the methods imports a method from a file located in a “server” directory, i.e not loaded at the client.
After I switched to the ValidatedMethod, the page crashed because it didn’t found the file.
When I moved the file out from this directory everything worked as expected.

I wonder why this didn’t happened with the traditional .call implementation.
I don’t really like that this file is loaded at the client as it handles server side only functionality.

Any thoughts?

Best regards,

If you don’t want to send that method code to the client just leave your ValidatedMethod files inside the server folder. You then keep your method calls on the client like before.

Why it worked before? Because it doesn’t matter if methods are defined on the client as long as they are on the server and you call them with `‘yourMethod’). So it seems like you defined your methods only server side. You then lose, of course, latency compensation (or what it’s also called Optimistic UI).

On the client basically it doesn’t matter if you import your ValidatedMethod and execute it or just call it “the traditional” way. The benefit you get from ValidatedMethod on the client is that you can call the validation function independently to your main method logic.

The easiest way to fix this is to wrap your import inside an if (Meteor.isServer) { block in the run method.

Thanks for all the responses!