Skip to content

Commit e9186d8

Browse files
Small changes to DB option handling. (#264)
- No longer accept an array for MongoDB options. - Fix passing an IORedis instance for the `redis` option. - Put default connection URIs in constants.
1 parent 42675b9 commit e9186d8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Uwave.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const MongooseConnection = mongoose.Connection;
2323

2424
const kSources = Symbol('Media sources');
2525

26+
const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave';
27+
const DEFAULT_REDIS_URL = 'redis://localhost:6379';
28+
2629
type UwaveOptions = {
2730
useDefaultPlugins: ?bool,
2831
mongo: ?string|Object,
@@ -72,27 +75,25 @@ export default class UWaveServer extends EventEmitter {
7275
}
7376

7477
parseOptions(options: UwaveOptions) {
75-
if (Array.isArray(options.mongo)) {
76-
this.mongo = mongoose.createConnection(...options.mongo);
77-
} else if (typeof options.mongo === 'string' || isPlainObject(options.mongo)) {
78+
if (typeof options.mongo === 'string' || isPlainObject(options.mongo)) {
7879
this.mongo = mongoose.createConnection(options.mongo);
7980
} else if (options.mongo instanceof MongooseConnection) {
8081
this.mongo = options.mongo;
8182
} else {
82-
this.mongo = mongoose.createConnection('mongodb://localhost:27017/uwave');
83+
this.mongo = mongoose.createConnection(DEFAULT_MONGO_URL);
8384
}
8485

8586
if (typeof options.redis === 'string') {
8687
this.redis = new Redis(options.redis, { lazyConnect: true });
87-
} else if (typeof options.redis === 'object') {
88+
} else if (isPlainObject(options.redis)) {
8889
this.redis = new Redis(options.redis.port, options.redis.host, {
8990
...options.redis.options,
9091
lazyConnect: true,
9192
});
9293
} else if (options.redis instanceof Redis) {
9394
this.redis = options.redis;
9495
} else {
95-
this.redis = new Redis({ lazyConnect: true });
96+
this.redis = new Redis(DEFAULT_REDIS_URL, { lazyConnect: true });
9697
}
9798

9899
Object.assign(this.options, options);

0 commit comments

Comments
 (0)