正在显示
2 个修改的文件
包含
26 行增加
和
24 行删除
@@ -3,23 +3,24 @@ | @@ -3,23 +3,24 @@ | ||
3 | 3 | ||
4 | var mongoose = require('mongoose') | 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 | var connection = mongoose.createConnection( | 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 | connection.on('open', function() { | 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,18 +5,19 @@ var express = require('express') | ||
5 | var session = require('express-session') | 5 | var session = require('express-session') |
6 | var RedisStore = require('connect-redis')(session) | 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 | connection.on('connect', function() { | 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' ] |
请
注册
或
登录
后发表评论