Comparing version 0.2.7 to 0.2.8
@@ -0,1 +1,5 @@ | ||
// creates an endpoint with given HTTP method, URL path and dispatch (function) | ||
// (method argument is optional) | ||
// endpoints are evaluated in server.js and | ||
// dispatch(request, response) is called if path/method matches | ||
module.exports = function(method, path, dispatch) { | ||
@@ -2,0 +6,0 @@ return { |
@@ -8,10 +8,4 @@ var util = require("util"), | ||
static = require("node-static"), | ||
mongodb = require("mongodb"); | ||
database = require('./database'); | ||
// Don't crash on errors. | ||
process.on("uncaughtException", function(error) { | ||
util.log("uncaught exception: " + error); | ||
util.log(error.stack); | ||
}); | ||
// And then this happened: | ||
@@ -33,7 +27,10 @@ websprocket.Connection = require("../../node_modules/websocket-server/lib/ws/connection"); | ||
// MongoDB driver configuration. | ||
var server_options = {auto_reconnect: true}, | ||
db_options = {safe: false}; | ||
module.exports = function(options) { | ||
module.exports = function(options) { | ||
// Don't crash on errors. | ||
process.on("uncaughtException", function(error) { | ||
util.log("uncaught exception: " + error); | ||
util.log(error.stack); | ||
}); | ||
var server = {}, | ||
@@ -45,4 +42,2 @@ primary = http.createServer(), | ||
endpoints = {ws: [], http: []}, | ||
mongo = new mongodb.Server(options["mongo-host"], options["mongo-port"], server_options), | ||
db = new mongodb.Db(options["mongo-database"], mongo, db_options), | ||
id = 0; | ||
@@ -79,5 +74,5 @@ | ||
function callback(response) { | ||
var callback = function(response) { | ||
connection.sendUTF(JSON.stringify(response)); | ||
} | ||
}; | ||
@@ -154,14 +149,4 @@ callback.id = ++id; | ||
util.log("starting mongodb client"); | ||
db.open(function(error) { | ||
database.open(options, function (error, db) { | ||
if (error) throw error; | ||
if (options["mongo-username"] == null) return ready(); | ||
db.authenticate(options["mongo-username"], options["mongo-password"], function(error, success) { | ||
if (error) throw error; | ||
if (!success) throw new Error("authentication failed"); | ||
ready(); | ||
}); | ||
}); | ||
// Start the server! | ||
function ready() { | ||
server.register(db, endpoints); | ||
@@ -179,3 +164,3 @@ meta = require("./event").putter(db); | ||
} | ||
} | ||
}); | ||
}; | ||
@@ -182,0 +167,0 @@ |
{ | ||
"name": "cube", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "A system for analyzing time series data using MongoDB and Node.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,9 +8,7 @@ var vows = require("vows"), | ||
var port = ++test.port, server = cube.server({ | ||
"mongo-host": "localhost", | ||
"mongo-port": 27017, | ||
"mongo-database": "cube_test", | ||
"http-port": port | ||
}); | ||
var server = cube.server(test.config), | ||
port = test.config["http-port"]; | ||
console.log('collector port %s', port); | ||
server.register = cube.collector.register; | ||
@@ -34,3 +32,3 @@ | ||
type: "test", | ||
time: new Date, | ||
time: new Date(), | ||
data: { | ||
@@ -51,3 +49,3 @@ foo: "bar" | ||
type: "test", | ||
time: new Date, | ||
time: new Date(), | ||
data: { | ||
@@ -54,0 +52,0 @@ foo: "bar" |
@@ -1,6 +0,6 @@ | ||
var mongodb = require("mongodb"), | ||
var database = require("../lib/cube/database"), | ||
util = require("util"), | ||
http = require("http"); | ||
exports.port = 1083; | ||
var config = exports.config = require('./test-config'); | ||
@@ -11,6 +11,4 @@ exports.batch = function(batch) { | ||
topic: function() { | ||
var client = new mongodb.Server("localhost", 27017), | ||
db = new mongodb.Db("cube_test", client, { safe: false }), | ||
cb = this.callback; | ||
db.open(function(error) { | ||
var cb = this.callback; | ||
database.open(config, function(error, db) { | ||
if (error) { | ||
@@ -24,3 +22,3 @@ return cb(error); | ||
if (!--collectionsRemaining) { | ||
cb(null, {client: client, db: db}); | ||
cb(null, {db: db}); | ||
} | ||
@@ -32,5 +30,3 @@ } | ||
teardown: function(test) { | ||
if (test.client.isConnected()) { | ||
test.client.close(); | ||
} | ||
test.db.close(); | ||
} | ||
@@ -37,0 +33,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
742680
53
18636