From 3b772f3a16c097c9d18a5a9388d3304dc1b2a601 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Fri, 29 Jan 2016 15:16:27 +0100 Subject: [PATCH 01/12] v1.3.0 RC --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4148b96..48cbf96f 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DADI API -![Build Status](http://img.shields.io/badge/Release-1.2.2-green.svg?style=flat-square) ![Coverage](https://img.shields.io/badge/Coverage-89%-yellow.svg?style=flat-square) +![Build Status](http://img.shields.io/badge/Release-1.3.0-green.svg?style=flat-square) ![Coverage](https://img.shields.io/badge/Coverage-89%-yellow.svg?style=flat-square) ## Overview diff --git a/package.json b/package.json index 879f357c..663d4cb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dadi-api", - "version": "1.2.2", + "version": "1.3.0", "main": "main.js", "scripts": { "test": "env NODE_ENV=test ./node_modules/.bin/istanbul cover -x **/workspace/** --report cobertura --report text --report html --report lcov ./node_modules/.bin/_mocha test", From 6aaa412ece45972511dcec60bad82434986b1733 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 00:07:21 +0800 Subject: [PATCH 02/12] Removed auto-creation of api docs path which should only happen if api-doc module is installed. Fixed #13. --- dadi/lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dadi/lib/index.js b/dadi/lib/index.js index dad43465..8100c9b4 100755 --- a/dadi/lib/index.js +++ b/dadi/lib/index.js @@ -110,7 +110,6 @@ Server.prototype.loadPaths = function(paths, done) { options.collectionPath = path.resolve(paths.collections || __dirname + '/../../workspace/collections'); options.endpointPath = path.resolve(paths.endpoints || __dirname + '/../../workspace/endpoints'); - options.docPath = path.resolve(paths.docs || __dirname + '/../../workspace/docs'); var idx = 0; From e50f06517045df0adbd7b0dd6a2a35797ec678fc Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:26:01 +0800 Subject: [PATCH 03/12] remove commented out test --- test/unit/cache.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/test/unit/cache.js b/test/unit/cache.js index 710892b4..174f8fde 100755 --- a/test/unit/cache.js +++ b/test/unit/cache.js @@ -272,32 +272,4 @@ describe('Cache', function (done) { }); }) - // it('should call file system stat', function (done) { - // - // var stub = sinon.stub(fs, 'stat', function (path, done) { - // stub.called.should.be.true; - // - // var args = stub.getCall(0).args; - // var pathName = args[0]; - // - // // pathName should be hex string json file - // pathName.should.match(/[a-g1-9]+\.json$/); - // args[1].should.be.Function; - // - // stub.restore(); - // - // done(); - // }); - // - // request('http://' + config.get('server.host') + ':' + config.get('server.port')) - // .get('/vtest/testdb/test-schema') - // .set('Authorization', 'Bearer ' + bearerToken) - // .expect(200) - // .end(function (err, res) { - // if (err) return done(err); - // - // done(); - // }); - // - // }); }); From 079e45ecf86fb2e7827c8cc0e123220def9efe44 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:27:08 +0800 Subject: [PATCH 04/12] modify search for endpoint to use path-to-regex --- dadi/lib/cache/index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dadi/lib/cache/index.js b/dadi/lib/cache/index.js index 0095c4b0..b7cff469 100755 --- a/dadi/lib/cache/index.js +++ b/dadi/lib/cache/index.js @@ -2,6 +2,7 @@ var crypto = require('crypto'); var fs = require('fs'); var mkdirp = require('mkdirp'); var path = require('path'); +var pathToRegexp = require('path-to-regexp'); var redis = require('redis'); var redisRStream = require('redis-rstream'); var redisWStream = require('redis-wstream'); @@ -57,14 +58,9 @@ module.exports = function(server) { Cache.prototype.cachingEnabled = function(req) { var options = {}; var endpoints = this.server.components; - var requestUrl = url.parse(req.url, true).pathname; + var requestPath = url.parse(req.url, true).pathname; - // var query = url.parse(req.url, true).query; - // if (query.hasOwnProperty('cache') && query.cache === 'false') { - // return false; - // } - - var endpointKey = _.find(_.keys(endpoints), function (k){ return k.indexOf(url.parse(requestUrl).pathname) > -1; }); + var endpointKey = _.find(_.keys(endpoints), function (k) { return pathToRegexp(k).exec(requestPath); }); if (!endpointKey) return false; From baa8e9b84fbf0a194e7baba80bf29df368f78cf0 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:28:44 +0800 Subject: [PATCH 05/12] ignore redis dump file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bf278940..9cdb0da9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ npm-debug.log cache/api/* log/*.log coverage/ +dump.rdb # Config config.json From 447e7a2ff44eecf95e9cfd9f002865d34c873eb8 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Fri, 29 Jan 2016 15:16:27 +0100 Subject: [PATCH 06/12] v1.3.0 RC --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4148b96..48cbf96f 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DADI API -![Build Status](http://img.shields.io/badge/Release-1.2.2-green.svg?style=flat-square) ![Coverage](https://img.shields.io/badge/Coverage-89%-yellow.svg?style=flat-square) +![Build Status](http://img.shields.io/badge/Release-1.3.0-green.svg?style=flat-square) ![Coverage](https://img.shields.io/badge/Coverage-89%-yellow.svg?style=flat-square) ## Overview diff --git a/package.json b/package.json index 879f357c..663d4cb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dadi-api", - "version": "1.2.2", + "version": "1.3.0", "main": "main.js", "scripts": { "test": "env NODE_ENV=test ./node_modules/.bin/istanbul cover -x **/workspace/** --report cobertura --report text --report html --report lcov ./node_modules/.bin/_mocha test", From 8a21c3effd00a661d5174c669d6cd4f2aebc0ecc Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 00:07:21 +0800 Subject: [PATCH 07/12] Removed auto-creation of api docs path which should only happen if api-doc module is installed. Fixed #13. --- dadi/lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dadi/lib/index.js b/dadi/lib/index.js index 1ec4b2c7..9af0aad7 100755 --- a/dadi/lib/index.js +++ b/dadi/lib/index.js @@ -119,7 +119,6 @@ Server.prototype.loadPaths = function(paths, done) { options.collectionPath = path.resolve(paths.collections || __dirname + '/../../workspace/collections'); options.endpointPath = path.resolve(paths.endpoints || __dirname + '/../../workspace/endpoints'); - options.docPath = path.resolve(paths.docs || __dirname + '/../../workspace/docs'); var idx = 0; From 79f48f70e3d41b182ce96a3afab882f2d7987ea7 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:26:01 +0800 Subject: [PATCH 08/12] remove commented out test --- test/unit/cache.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/test/unit/cache.js b/test/unit/cache.js index 710892b4..174f8fde 100755 --- a/test/unit/cache.js +++ b/test/unit/cache.js @@ -272,32 +272,4 @@ describe('Cache', function (done) { }); }) - // it('should call file system stat', function (done) { - // - // var stub = sinon.stub(fs, 'stat', function (path, done) { - // stub.called.should.be.true; - // - // var args = stub.getCall(0).args; - // var pathName = args[0]; - // - // // pathName should be hex string json file - // pathName.should.match(/[a-g1-9]+\.json$/); - // args[1].should.be.Function; - // - // stub.restore(); - // - // done(); - // }); - // - // request('http://' + config.get('server.host') + ':' + config.get('server.port')) - // .get('/vtest/testdb/test-schema') - // .set('Authorization', 'Bearer ' + bearerToken) - // .expect(200) - // .end(function (err, res) { - // if (err) return done(err); - // - // done(); - // }); - // - // }); }); From 1d9eb3f50177b7b6d02b1627c1213c25673d1c64 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:27:08 +0800 Subject: [PATCH 09/12] modify search for endpoint to use path-to-regex --- dadi/lib/cache/index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dadi/lib/cache/index.js b/dadi/lib/cache/index.js index 0095c4b0..b7cff469 100755 --- a/dadi/lib/cache/index.js +++ b/dadi/lib/cache/index.js @@ -2,6 +2,7 @@ var crypto = require('crypto'); var fs = require('fs'); var mkdirp = require('mkdirp'); var path = require('path'); +var pathToRegexp = require('path-to-regexp'); var redis = require('redis'); var redisRStream = require('redis-rstream'); var redisWStream = require('redis-wstream'); @@ -57,14 +58,9 @@ module.exports = function(server) { Cache.prototype.cachingEnabled = function(req) { var options = {}; var endpoints = this.server.components; - var requestUrl = url.parse(req.url, true).pathname; + var requestPath = url.parse(req.url, true).pathname; - // var query = url.parse(req.url, true).query; - // if (query.hasOwnProperty('cache') && query.cache === 'false') { - // return false; - // } - - var endpointKey = _.find(_.keys(endpoints), function (k){ return k.indexOf(url.parse(requestUrl).pathname) > -1; }); + var endpointKey = _.find(_.keys(endpoints), function (k) { return pathToRegexp(k).exec(requestPath); }); if (!endpointKey) return false; From 3e1db7448f0e7eb0e2f04f89fdea6499990e4fd6 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Wed, 3 Feb 2016 17:28:44 +0800 Subject: [PATCH 10/12] ignore redis dump file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bf278940..9cdb0da9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ npm-debug.log cache/api/* log/*.log coverage/ +dump.rdb # Config config.json From b02f3a36a2718e2129c6499025c6ad94f7c15ba4 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Tue, 9 Feb 2016 10:57:00 +0800 Subject: [PATCH 11/12] reinstate create-client script --- utils/create-client.js | 19 +++++++++++++++++++ utils/load-ref-db.js | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 utils/create-client.js diff --git a/utils/create-client.js b/utils/create-client.js new file mode 100755 index 00000000..4db40a39 --- /dev/null +++ b/utils/create-client.js @@ -0,0 +1,19 @@ +// Create a client object, enabling access to the api +var connection = require(__dirname + '/../dadi/lib/model/connection'); +var config = require(__dirname + '/../config'); + +var conn = connection(config.get('auth.database')); +var clientCollectionName = config.get('auth.clientCollection'); + +conn.on('connect', function (db) { + + // Note: this is for QA testing or example purposes only + db.collection(clientCollectionName).insert({ + clientId: 'testClient', + secret: 'superSecret' + }, function (err) { + if (err) throw err; + + conn.mongoClient.close(); + }); +}) diff --git a/utils/load-ref-db.js b/utils/load-ref-db.js index 45ea033a..44aa1f32 100755 --- a/utils/load-ref-db.js +++ b/utils/load-ref-db.js @@ -1,4 +1,3 @@ -// Create a client object, enabling access to the api var connection = require(__dirname + '/../dadi/lib/model/connection'); var config = require(__dirname + '/../config').database; From 8aaa8683a75e30fee6057673f71ab36588dc45e1 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Thu, 11 Feb 2016 11:07:12 +0800 Subject: [PATCH 12/12] Database replicaSet property should be a string, not a Boolean --- config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.js b/config.js index 7fd4c462..757a0f05 100644 --- a/config.js +++ b/config.js @@ -60,7 +60,7 @@ var conf = convict({ }, replicaSet: { doc: "", - format: Boolean, + format: String, default: false }, enableCollectionDatabases: {