Meteor: code inside the Meteor.isServer block read from the client?

I am confused when you will use the isServer block to enter data. Obviously database calls, etc. Does this appear in the client browser?

+6
source share
3 answers

I would advise against using this instead of putting your things in folders as indicated in unofficial meteor faq

Even if you use if (Meteor.isServer) {...} , this block will still be sent to the client if you do not use the folder structure above ie, placing it in /server . But it will ignore all the code inside it.

In the server-side code, you should put the code that you want to run only on the server, i.e. publish features and data that will be more sensitive, and the user should not have access.

+7
source

I think it is sent to the client if it is not in the server folder. In response to one of the comments about sharing global variables, I used this template. Create the same global variable in the client and server folders, respectively, and once outside of these folders for any common code. Initialize the global variable at each location by testing to verify that it already exists.

 MyVar = typeof MyVar === 'undefined' ? {} : MyVar; 

Then just put the methods where you need them. For example, I will have a User object with a method that checks if the user is allowed. I will declare the method once on the global server of the server and once on the client global user. The methods are different because the server version checks the user properties of the user object that are not available on the client. Then, in the Meteor.methods method, which runs both on the client and on the server, you can call the authorization method, and it will call different methods depending on whether it works on the client or server.

+1
source

I asked myself the same question today and came across this package:

https://github.com/mquandalle/meteor-minifiers

Meteor doesn't seem to delete the default Meteor.isServer blocks. See discussion:

https://groups.google.com/forum/#!topic/meteor-talk/iHat47f6iGE

I have not used it now, but it looks promising.

If you do not want to use the additional package, I would recommend using the client and server folders. Clients send only files in the client folder.

+1
source

All Articles