mongodb-rest
Advanced tools
Comparing version 0.10.11 to 0.10.12
var querystring = require('querystring'); | ||
var uuid = require('node-uuid'); | ||
var mongodb = require("mongodb"); | ||
var MongoClient = mongodb.MongoClient; | ||
var connection = require('./connection'); | ||
@@ -51,3 +51,3 @@ var DEFAULT_TOKEN_EXPIRATION_TIME_HOURS = 8; | ||
MongoClient.connect(config.auth.tokenDBConnection, function (err, tokensDb) { | ||
connection.connect(config.auth.tokenDBConnection, function (err, tokensDb) { | ||
@@ -62,3 +62,2 @@ if (err) { | ||
if (err) { | ||
tokensDb.close(); | ||
logger.error('Error getting collection ' + tokensCollectionName + ': ' + err.message); | ||
@@ -72,3 +71,2 @@ res.status(500).json({ error: err }); | ||
if (err) { | ||
tokensDb.close(); | ||
logger.error('Error finding token ' + token + ' in database: ' + err.message); | ||
@@ -80,3 +78,2 @@ res.status(500).json({ error: err }); | ||
if (!token) { | ||
tokensDb.close(); | ||
logger.warning('Unauthorized access - token ' + token + ' not found in database'); | ||
@@ -96,4 +93,2 @@ res.status(401).json( {error: 'Unauthorized - no matching token found'} ); | ||
tokensDb.close(); | ||
next(); | ||
@@ -124,3 +119,3 @@ }); | ||
MongoClient.connect(config.auth.usersDBConnection, function (err, usersDb) { | ||
connection.connect(config.auth.usersDBConnection, function (err, usersDb) { | ||
@@ -137,3 +132,2 @@ if (err) { | ||
logger.error('Failed to get collection ' + usersCollectionName + ': ' + err.message); | ||
usersDb.close(); | ||
res.status(500).json({ message: 'Server error' }); | ||
@@ -144,4 +138,2 @@ return; | ||
usersCollection.findOne({ username: username }, function (err, user) { | ||
usersDb.close(); | ||
if (err) { | ||
@@ -163,3 +155,3 @@ logger.error('Error finding user ' + username + ': ' + err.message); | ||
MongoClient.connect(config.auth.tokenDBConnection, function (err, tokensDb) { | ||
connection.connect(config.auth.tokenDBConnection, function (err, tokensDb) { | ||
@@ -176,3 +168,2 @@ if (err) { | ||
logger.error('Failed to get collection ' + tokensCollectionName + ': ' + err.message); | ||
tokensDb.close(); | ||
res.status(500).json({ message: 'Server error' }); | ||
@@ -186,3 +177,2 @@ return; | ||
logger.error('Error finding token for user ' + user._id + ': ' + err.message); | ||
tokensDb.close(); | ||
res.status(500).json({ message: 'Server error' }); | ||
@@ -201,3 +191,2 @@ return; | ||
tokensDb.close(); | ||
res.status(200).json({ | ||
@@ -224,4 +213,2 @@ token: token.token, | ||
tokensCollection.save(newToken, function (err) { | ||
tokensDb.close(); | ||
if (err) { | ||
@@ -228,0 +215,0 @@ logger.error('Failed to save new token ' + newToken.token + ' for user ' + user._id + ' to database: ' + err.message); |
@@ -11,3 +11,3 @@ /* | ||
var mongodb = require("mongodb"); | ||
var MongoClient = mongodb.MongoClient; | ||
var connection = require('./connection'); | ||
var auth = require('./auth'); | ||
@@ -144,3 +144,3 @@ var BSON = mongodb.BSONPure; | ||
MongoClient.connect(dbConnectionStr, function (err, db) { | ||
connection.connect(dbConnectionStr, function (err, db) { | ||
@@ -159,3 +159,2 @@ if (err) { | ||
if (err) { | ||
db.close(); | ||
logger.error('Error listing database: ' + err.message); | ||
@@ -171,3 +170,2 @@ res.status(500).json({ message: 'Server error' }); | ||
res.json(dbNames); | ||
db.close(); | ||
}); | ||
@@ -182,3 +180,3 @@ }); | ||
MongoClient.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
connection.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
@@ -193,3 +191,2 @@ if (err) { | ||
if (err) { | ||
db.close(); | ||
logger.error('Error getting collection names: ' + err.message); | ||
@@ -206,3 +203,2 @@ res.status(500).json({ message: 'Server error' }); | ||
res.json(collectionNames); | ||
db.close(); | ||
}); | ||
@@ -232,3 +228,3 @@ }); | ||
MongoClient.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
connection.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
@@ -243,3 +239,2 @@ if (err) { | ||
if (err) { | ||
db.close(); | ||
logger.error('Error getting collection ' + collection + ': ' + err.message); | ||
@@ -252,3 +247,2 @@ res.status(500).json({ message: 'Server error' }); | ||
if (err) { | ||
db.close(); | ||
logger.error('Error finding document(s): ' + err.message); | ||
@@ -261,3 +255,2 @@ res.status(500).json({ message: 'Server error' }); | ||
if (err) { | ||
db.close(); | ||
logger.error('Error getting database cursor as array: ' + err.message); | ||
@@ -285,4 +278,2 @@ res.status(500).json({ message: 'Server error' }); | ||
} | ||
db.close(); | ||
}); | ||
@@ -300,3 +291,3 @@ }); | ||
if(req.body) { | ||
MongoClient.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
connection.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
@@ -311,3 +302,2 @@ if (err) { | ||
if (err) { | ||
db.close(); | ||
logger.error('Error getting collection ' + collection + ': ' + err.message); | ||
@@ -323,3 +313,2 @@ res.status(500).json({ message: 'Server error' }); | ||
if (err) { | ||
db.close(); | ||
logger.error('Error inserting into collection ' + collection + ': ' + err.message); | ||
@@ -332,3 +321,2 @@ res.status(500).json({ message: 'Server error' }); | ||
res.status(201).json({ ok: 1 }); | ||
db.close(); | ||
} | ||
@@ -349,3 +337,3 @@ ); | ||
MongoClient.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
connection.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
@@ -360,3 +348,2 @@ if (err) { | ||
if (err) { | ||
db.close(); | ||
logger.error('Error getting collection ' + collection + ': ' + err.message); | ||
@@ -369,3 +356,2 @@ res.status(500).json({ message: 'Server error' }); | ||
res.json({ ok: 1 }); | ||
db.close(); | ||
}); | ||
@@ -382,3 +368,3 @@ }); | ||
MongoClient.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
connection.connect(dbConnectionStr + '/' + req.params.db, function (err, db) { | ||
@@ -406,3 +392,2 @@ if (err) { | ||
res.json({ ok: 1 }); | ||
db.close(); | ||
}); | ||
@@ -409,0 +394,0 @@ }); |
{ | ||
"name": "mongodb-rest", | ||
"description": "REST API Server for MongoDB", | ||
"version": "0.10.11", | ||
"version": "0.10.12", | ||
"author": "Ashley Davis <ashley@codecapers.com.au>", | ||
@@ -16,2 +16,6 @@ "contributors": [ | ||
{ | ||
"name": "Ryan Carmichael", | ||
"email": "ryan.carmichael@elabsolutions.com" | ||
}, | ||
{ | ||
"name": "Tom de Grunt", | ||
@@ -18,0 +22,0 @@ "email": "tom@degrunt.nl" |
@@ -13,2 +13,4 @@ mongodb-rest [![Build Status](https://travis-ci.org/codecapers/mongodb-rest.png)](https://travis-ci.org/codecapers/mongodb-rest) | ||
Simple connection pooling has been added by @elabrc. | ||
A simple token-based authentication has been added to mongodb-rest (thanks to @ZECTBynmo). This is a prototype feature only and may change in the future. I am considering making authentication plugin-based so you can roll your own if necessary. If you have any thoughts on how this should work please let us know. | ||
@@ -15,0 +17,0 @@ |
@@ -10,2 +10,3 @@ 'use strict'; | ||
var Q = require('q'); | ||
var connection = require('../lib/connection'); | ||
@@ -247,2 +248,3 @@ // | ||
restServer.stopServer(); | ||
connection.closeAll(); | ||
}, | ||
@@ -249,0 +251,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
17
244
94409