提交 520d584c206c2aad306008de07d3938265f1d0b8

作者 Nick Baugh
1 个父辈 b4ccbc63

added mongo and redis components

正在显示 2 个修改的文件 包含 26 行增加24 行删除
... ... @@ -3,23 +3,24 @@
3 3
4 4 var mongoose = require('mongoose')
5 5
6   -var lib
  6 +exports = module.exports = function(logger, settings) {
7 7
8   -module.exports = function(_lib) {
9   - lib = _lib
10   - return mongo
11   -}
12   -
13   -function mongo(callback) {
14 8 var connection = mongoose.createConnection(
15   - lib.config.db.host,
16   - lib.config.db.dbname,
17   - lib.config.db.port,
18   - lib.config.db.opts
  9 + settings.mongo.host,
  10 + settings.mongo.dbname,
  11 + settings.mongo.port,
  12 + settings.mongo.opts
19 13 )
20   - connection.on('error', lib.logger.error)
  14 +
  15 + connection.on('error', logger.error)
  16 +
21 17 connection.on('open', function() {
22   - lib.logger.info('mongo connection opened')
  18 + logger.info('mongo connection opened')
23 19 })
24   - callback(null, connection)
  20 +
  21 + return connection
  22 +
25 23 }
  24 +
  25 +exports['@singleton'] = true
  26 +exports['@require'] = [ 'logger', 'settings' ]
... ...
... ... @@ -5,18 +5,19 @@ var express = require('express')
5 5 var session = require('express-session')
6 6 var RedisStore = require('connect-redis')(session)
7 7
8   -var lib
  8 +exports = module.exports = function(logger, settings) {
9 9
10   -module.exports = function(_lib) {
11   - lib = _lib
12   - return redis
13   -}
  10 + var connection = new RedisStore(settings.redis)
  11 +
  12 + connection.on('error', logger.error)
14 13
15   -function redis(callback) {
16   - var connection = new RedisStore(lib.config.redis)
17   - connection.on('error', lib.logger.error)
18 14 connection.on('connect', function() {
19   - lib.logger.info('redis connected')
  15 + logger.info('redis connected')
20 16 })
21   - callback(null, connection)
  17 +
  18 + return connection
  19 +
22 20 }
  21 +
  22 +exports['@singleton'] = true
  23 +exports['@require'] = [ 'logger', 'settings' ]
... ...
注册登录 后发表评论