I use an environment variable when I run my meteor project like this
MYVAR1="foo bar sdf" MYVAR2=0 meteor
then in the file [root] /lib/constants.js I have
ENV = ["sjobs", "unisight", "dfgdfsgf"];
AUTHENTICATION = true;
if (Meteor.isClient) {
Meteor.call("getGlobals", function (error, result) {
"use strict";
if (error === undefined) {
AUTHENTICATION = result.AUTHENTICATION;
ENV= result.ENV;
console.log(result);
} else {
console.error(error);
}
});
}
if (Meteor.isServer) {
var univasENV = ["urb", "unisight", "sjobs", "unicloud"];
var tmpenv;
if (process.env.MYVAR2 !== undefined && parseInt(process.env.MYVAR2, 10) === 1) {
AUTHENTICATION = false;
}
if (process.env.MYVAR1 !== undefined) {
tmpenv = process.env.MYVAR1.split(" ");
ENV = [];
_.each(tmpenv, function (value) {
"use strict";
if (univasENV.indexOf(value) !== -1) {
ENV.push(value);
}
});
}
}
in another [root] /server/methods.js file I have:
Meteor.methods({
getGlobals: function(){
"use strict";
console.log(AUTHENTICATION, ENV);
return {
auth: AUTHENTICATION,
env: ENV
};
}
});
the server side is working as I expect, but the client-side code is executed after everything has been displayed or loaded. The problem here is Meteor.call (), which runs async, and I cannot use (as far as I know) Meteor.wrapAsync ().
I also tried to write the values that I need in the collection and then read them from the client (all this in [root] /lib/constants.js), but it behaves exactly like a method / call.
so the question is, how can I pass some values from the server to the client at the very beginning?