我在向Heroku部署mean.io应用程序时遇到了麻烦。这篇文章描述了我创建应用程序并尝试部署它的步骤。我做错了什么?
首先,我启动一个Mongo守护进程:
$ mongod
然后创建一个mean.io应用程序:
$ npm install -g mean-cli
$ mean init myNewApp
> app name? myNewApp
> help us improve the mean network? n
> set up first admin user? y
> email: user@example.com
> pass: mypassword
$ cd myNewApp
$ mean postinstall
$ npm install
$ bower install
$ gulp
默认的mean.io gulp任务启动本地网络服务器,我可以登录该应用程序。下一步是创建一个Heroku应用程序:
$ heroku create # this creates https://shrouded-stream-2828.herokuapp.com
从compose.io添加一个MongoDB插件。这是通过以下步骤完成的:
# In the Heroku web console, select the Heroku application.
# Click edit Add-ons, find Compose MongoDB, and press save.
# Click on "Compose MongoDB" link, click the "Admin" tab
# Click the "Users" tab, click the "Add user" button, adding the user:
db.addUser('meanadmin','mypassword')
# And hit the "Add user" button to actually add the user.
# Copy the URL from the Overview tab:
mongodb://meanadmin:mypassword@candidate.2.mongolayer.com:10479,candidate.3.mongolayer.com:10419/app15307042
使用此URL,在文本编辑器中导航到/path/to/myNewApp/config/env/production.js并替换" db"的值。上面带有Mongo URL的属性,如:
db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost') + '/mean-prod',
becomes...
db: 'mongodb://meanadmin:mypassword@candidate.2.mongolayer.com:10479,candidate.3.mongolayer.com:10419/app15307042',
提交更改,然后推送到Heroku:
$ git add .
$ git commit -m 'adding mongodb'
$ git fetch --unshallow
$ git push heroku master
$ heroku open
经过长时间停顿后,会出现以下错误:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
如何将此应用程序部署到Heroku?例如,我不确定是否将Mongo URL复制到了正确的位置。我做错了什么?