我是Meteor新手,正在設置dev,stage和production Meteor.settings。Meteor.js - 生產Meteor.settings引發TypeError undefined
使用「開發」設置,我的本地系統上的一切工作正常,但是當我捆綁它並在數字海洋上運行時,它會中斷。如果我刪除了對設置文件的調用,並將其替換爲文本字符串,則一切正常。
這裏是設置文件,命名爲「1_settings.js」所有其他的JS文件加載之前(至少在理論上):
console.log("=> inside 1_settings.js");
environment = process.env.NODE_ENV || "development";
var settings = {
development: {
public: {},
private: {
"firstUser": {
"id": "ZsKaw3kSbQ4uSvzJg"
},
}
},
staging: {
public: {},
private: {}
},
production: {
public: {},
private: {
"firstUser": {
"id": "oPMfpAuwQ3nuTdpTA"
},
}
}
};
if (!process.env.METEOR_SETTINGS) {
console.log("=> No METEOR_SETTINGS passed in, using locally defined settings.");
if (environment === "production") {
Meteor.settings = settings.production;
} else if (environment === "staging") {
Meteor.settings = settings.staging;
} else {
Meteor.settings = settings.development;
}
// Push a subset of settings to the client.
if (Meteor.settings && Meteor.settings.public) {
__meteor_runtime_config__.PUBLIC_SETTINGS = Meteor.settings.public;
}
}
這裏是我使用的設置:
如果(Meteor.isServer){
var settings = Meteor.settings.private;
console.log("=> settings: " + JSON.stringify(settings));
Meteor.startup(function() {
// bootstrap the admin user if they exist -- You'll be replacing the id later
if (Meteor.users.findOne(settings["firstUser"]["id"]))
Roles.addUsersToRoles(settings["firstUser"]["id"], ['admin']);
正如你所看到的,它打破在上面的代碼中,第二個「如果」的聲明,其中我打電話的設置[「firstUser」] [「ID」],如下面的錯誤所示:
TypeError: Cannot read property 'firstUser' of undefined
at app/server/app.startup.js:8:42
at /home/qdev/bundle/programs/server/boot.js:175:5
/home/qdev/bundle/programs/server/node_modules/fibers/future.js:173
throw(ex);
^
很明顯,我明白settings屬性是undefind或null。我不明白的是爲什麼?即使我沒有設置$ NODE_ENV =生產(我有),它應該仍然回落到開發設置。幫助表示讚賞!
我看你正在檢查'METEOR_SETTINGS'以確定它沒有設置。也許這是由於某種原因在您的生產環境中設置的。 – Nate