Skip to content

Commit

Permalink
db secret
Browse files Browse the repository at this point in the history
  • Loading branch information
andyliwr committed Oct 27, 2018
1 parent cc08021 commit cedb5e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
19 changes: 13 additions & 6 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ var server = null
var port = normalizePort(config.port || '3000');

async function connectMongo() {
mongoose.Promise = global.Promise
mongoose.connection.on('error', console.error.bind(console, '连接数据库失败'))
return await mongoose.connect(config.mongo_url, {
useMongoClient: true,
})
mongoose.Promise = global.Promise
mongoose.connection.on('error', console.error.bind(console, '连接数据库失败'))
console.log('start to connect')
return await mongoose.connect(
config.mongo_url,
{
user: config.mongo_user,
pass: config.mongo_pass,
auth: { authdb: config.mongo_dbname, authMechanism: 'MONGODB-CR' },
useMongoClient: true
}
)
}

connectMongo().then(() => {
Expand Down Expand Up @@ -66,4 +73,4 @@ function onListening() {
'pipe ' + addr :
'port ' + addr.port;
debug('Listening on ' + bind);
}
}
7 changes: 6 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const config = {
port: 3001,
mongo_url: 'mongodb://localhost:27017/ldk-upload-img',
mongo_url: 'mongodb://127.0.0.1:27017/ldk-upload-img',
mongo_user: 'upload',
mongo_pass: '121960425upload',
redis_host: '127.0.0.1',
redis_port: '6379',
redis_pass: '121960425redis',
accessKey: 'pz1XaE-7IPSWuJjLTrjH3Rv9O5v0hj510O1ttMm6', //七牛账号的key值,https://portal.qiniu.com/user/key
secretKey: 'HB_zxxzxJ3YpKFAD3PC7egJvgx4yOp3t6Fg7xdYP',
bucket: 'upload', //空间名称
Expand Down
8 changes: 7 additions & 1 deletion utils/store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const Redis = require("ioredis")
const config = require('../config')
const { Store } = require("koa-session2")

class RedisStore extends Store {
constructor() {
super();
this.redis = new Redis(6379, 'localhost')
this.redis = new Redis({
port: config.redis_port, // Redis port
host: config.redis_host, // Redis host
family: 4, // 4 (IPv4) or 6 (IPv6)
password: config.redis_pass
})
}

async get(sid, ctx) {
Expand Down

0 comments on commit cedb5e6

Please sign in to comment.