当部署在heroku上时,Sails js连接恢复到开发

我一直在尝试在heroku上使用mongolab作为我的mongodb来部署我的sails应用程序。

我使用了以下连接,一个用于开发,一个用于生产:

local_mongo : { adapter : 'sails-mongo', host : 'localhost', port : 27017, database : "something" }, heroku_mongolab : { adapter : "sails-mongo", url : "mongodb://*****:******!@ds063160.mongolab.com:63160/something" } 

我也设置我的local.js文件使用开发环境,并在gitignore上的文件。

最后在我的development.js上做以下工作

 module.exports = { models: { connection: 'local_mongo' } }; 

在我的production.js

 module.exports = { /*************************************************************************** * Set the default database connection for models in the production * * environment (see config/connections.js and config/models.js ) * ***************************************************************************/ models: { connection: 'heroku_mongolab' } /*************************************************************************** * Set the port in the production environment to 80 * ***************************************************************************/ //port: 80 /*************************************************************************** * Set the log level in production environment to "silent" * ***************************************************************************/ //log: { // level: "silent" //} }; 

并在我的package.json我改变了开始脚本节点app.js –prod。 在本地运行时,一切都按预期工作,甚至当我运行npm start时,但是当我在heroku上部署并查看日志时,我发现它试图连接到本地主机mongodb。

这是一个错误还是我做错了什么?

你必须使用Procfile。 在应用程序的根目录下创build一个名为“Procfile”的文件,明确声明应该执行哪个命令来启动你的应用程序。 在你的情况下,要定义生产环境,请添加以下行:

web: NODE_ENV=production node app.js

如果您希望Heroku在生产环境中运行您的应用程序,则必须如下设置环境variables:

 heroku config:set NODE_ENV=production