UNPKG

mongoscope-client

Version:
36 lines (30 loc) 886 B
var scope = require('../'); var endpoint = 'http://scope.mongodb.land', seed = 'localhost:27017'; if(typeof window === 'undefined' || (window && window.location.origin === 'http://localhost:8080')){ endpoint = 'http://localhost:29017'; require('debug').enable('mongoscope*'); } module.exports = { client: null, createClient: function(opts){ opts = opts || {}; opts.scope = opts.scope || endpoint; opts.seed = opts.seed || seed; module.exports.client = scope(opts); return module.exports.client; }, before: function(done){ module.exports.createClient() .on('error', done) .on('readable', done.bind(null, null)); }, after: function(done){ if(!module.exports.client) return done(); module.exports.client.close(function(err){ if(err) return done(err); module.exports.client = null; done(); }); } };