Skip to content

Commit

Permalink
fix mongodb connect error
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhutu committed Jul 14, 2017
1 parent ff61258 commit 220c15a
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 93 deletions.
1 change: 1 addition & 0 deletions logs/development-error.log.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":33625,"level":50,"msg":"登录用户名错误 { username: '[email protected]' }","time":"2017-07-12T10:02:36.061Z","v":0}
6 changes: 0 additions & 6 deletions logs/development-error.log.1
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录用户名错误 { username: '[email protected]' }","time":"2017-07-10T07:58:54.206Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:22.462Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:39.735Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:57.960Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T08:00:15.718Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T08:01:35.288Z","v":0}
6 changes: 6 additions & 0 deletions logs/development-error.log.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录用户名错误 { username: '[email protected]' }","time":"2017-07-10T07:58:54.206Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:22.462Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:39.735Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T07:59:57.960Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T08:00:15.718Z","v":0}
{"name":"jackblog","hostname":"hugongzideMacBook-Air.local","pid":29883,"level":50,"msg":"登录密码错误 { username: '[email protected]' }","time":"2017-07-10T08:01:35.288Z","v":0}
174 changes: 95 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"koa-router": "^7.1.1",
"lodash": "^4.17.4",
"markdown-it": "^8.3.1",
"mongoose": "^4.11.1",
"mongoose": "^4.11.2",
"passport-github": "^1.1.0",
"passport-local": "^1.0.0",
"passport-qq": "0.0.3",
Expand All @@ -77,7 +77,7 @@
"xss": "^0.3.3"
},
"devDependencies": {
"ava": "^0.20.0",
"ava": "^0.21.0",
"ava-spec": "^1.0.1",
"babel-plugin-espower": "^2.3.2",
"babel-plugin-transform-runtime": "^6.23.0",
Expand All @@ -89,7 +89,7 @@
"nodemon": "^1.11.0",
"npm-run-all": "^4.0.0",
"nyc": "^11.0.3",
"sinon": "^2.3.7",
"sinon": "^2.3.8",
"superkoa": "^1.0.3",
"supertest": "^3.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion server/config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module.exports = {
//开发环境mongodb配置
mongo: {
uri: 'mongodb://localhost/jackblog-dev'
uri: `mongodb://${encodeURIComponent(process.env.MONGO_USERNAME || '')}:${encodeURIComponent(process.env.MONGO_PASSWORD || '')}@localhost:27017/jackblog-dev`
},
//开发环境redis配置
redis: {
Expand Down
4 changes: 2 additions & 2 deletions server/config/env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var all = {
mongo: {
options: {
useMongoClient: true,
user: process.env.MONGO_USERNAME || '',
pass: process.env.MONGO_PASSWORD || ''
// user: process.env.MONGO_USERNAME || '',
// pass: process.env.MONGO_PASSWORD || ''
}
},
//redis 配置
Expand Down
2 changes: 1 addition & 1 deletion server/config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
port: process.env.PORT || 8800,
//生产环境mongodb配置
mongo: {
uri: 'mongodb://' + MONGO_ADDR + '/jackblog'
uri: `mongodb://${encodeURIComponent(process.env.MONGO_USERNAME || '')}:${encodeURIComponent(process.env.MONGO_PASSWORD || '')}@${MONGO_ADDR}/jackblog`
},
//生产环境redis配置
redis: {
Expand Down
2 changes: 1 addition & 1 deletion server/config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// ===========================
module.exports = {
mongo: {
uri: 'mongodb://localhost/jackblog-test'
uri: `mongodb://${encodeURIComponent(process.env.MONGO_USERNAME || '')}:${encodeURIComponent(process.env.MONGO_PASSWORD || '')}@localhost:27017/jackblog-test`
},
redis: {
db: 2,
Expand Down
1 change: 1 addition & 0 deletions server/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const mongoose = require('mongoose')
const config = require('./config/env')

// 连接数据库.
console.log(config.mongo.uri)
mongoose.connect(config.mongo.uri, config.mongo.options)
const modelsPath = path.join(__dirname, 'model')
fs.readdirSync(modelsPath).forEach(function (file) {
Expand Down

0 comments on commit 220c15a

Please sign in to comment.