请关注我的小站:http://oideas.herokuapp.com/
首先,我们需要给数据库添加一个用户。点击红色框中的 Admin ,然后点击 Users 进入用户管理页面。在 username 和 password 处分别填写用户名和密码:
db.addUser('omind','jov.omind')
点击 Add user 添加用户。
module.exports = {
cookieSecret: 'ominds',
url: 'mongodb://omind:jov.omind@widmore.mongohq.com:10000/ominds'
};
其中的url为你自己的uri(请自觉替换哦)。
app.use(express.session({
secret: settings.cookieSecret,
key: settings.db,//cookie name
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
store: new MongoStore({
db: settings.db
})
}));
为:
app.use(express.session({
secret: settings.cookieSecret,
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
url: settings.url
}));
将models下的js文件做以下修改:
//var mongodb = require('./db');
2.添加代码:
var settings = require('../settings');
3.将所有
mongodb.open(function (err, db) {
修改为
mongodb.connect(settings.url, function (err, db) {
注意:假如你的电脑上已经安装了 Git ,那么在安装的时候选择 Custom Installation 并去掉安装 Git 的选项,否则选择 Full Installation 。
安装成功后,打开 Git Bash ,输入 heroku login
,然后输入在 Heroku 注册的帐号和密码进行登录。Git 会检测是否有 SSH 密钥,如果有,则使用此密钥并上传,如果没有,则创建一个密钥并上传。(你也可以使用heroku keys命令查看有没有keys,如果没有,可以使用heroku add:keys添加keys)
Tips:SSH 密钥通常用于授予用户访问服务器的权限。可将它们用于某些配置中,以便无需密码即可访问服务器。许多 PaaS 提供商都使用了此功能。
在工程的根目录下新建一个 Procfile 文件,添加如下内容:web: node app.js
Procfile 文件告诉了服务器该使用什么命令启动一个 web 服务,这里我们通过 node app.js
执行 Node 脚本。为什么这里声明了一个 web
类型呢?官方解释为:
The name “web” is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed.
打开 Git Bash ,切换到你的项目目录下面(windows环境,如果要切换磁盘使用 cd e: 命令),输入:
$ git init
$ git add .
$ git commit -m "init"
$ git remote add heroku git@heroku.com:yourAppName.git
$ git push heroku master
git add .
git commit - m "update"
git push heroku master
做好了。(如果发现,没有统计数据,不用担心,没事玩玩就可以了)