From bed9eb4f9b0ab1297d14d0cd788efac8339541f3 Mon Sep 17 00:00:00 2001 From: bredele Date: Fri, 28 Mar 2014 01:25:53 -0600 Subject: [PATCH 1/2] feathers use other feathers apps --- lib/application.js | 5 +++++ test/application.test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/application.js b/lib/application.js index 5b87c54c21..397f686e78 100644 --- a/lib/application.js +++ b/lib/application.js @@ -39,10 +39,15 @@ module.exports = { }, use: function (location, service) { + var hasServiceMethod = function (name) { return typeof service !== 'undefined' && typeof service[name] === 'function'; }; + if(hasServiceMethod('handle') && hasServiceMethod('set')){ + return this._super.call(this, location, service); + } + // Check for service (any object with at least one service method) if (_.some(this.methods, hasServiceMethod)) { return this.service(location, service); diff --git a/test/application.test.js b/test/application.test.js index 3fc9c1ae48..75e817d6e4 100644 --- a/test/application.test.js +++ b/test/application.test.js @@ -9,6 +9,19 @@ var fs = require('fs'); var feathers = require('../lib/feathers'); +describe("Express application", function() { + + it("should use express apps", function() { + var app = feathers(); + var child = feathers(); + + app.use('/path', child); + assert.equal(child.route, '/path'); + }); + +}); + + describe('Feathers application', function () { it('registers service and looks it up with and without leading and trailing slashes', function () { var dummyService = { From 9b1d4e36a4e455bbeeadac267e13897ca3bb0e7d Mon Sep 17 00:00:00 2001 From: bredele Date: Fri, 28 Mar 2014 01:32:28 -0600 Subject: [PATCH 2/2] refactor feathers use --- lib/application.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/application.js b/lib/application.js index 397f686e78..810bbc9eb9 100644 --- a/lib/application.js +++ b/lib/application.js @@ -40,21 +40,19 @@ module.exports = { use: function (location, service) { - var hasServiceMethod = function (name) { - return typeof service !== 'undefined' && typeof service[name] === 'function'; + var hasMethod = function() { + return _.some(arguments, function(name) { + return (service && typeof service[name] === 'function'); + }); }; - if(hasServiceMethod('handle') && hasServiceMethod('set')){ - return this._super.call(this, location, service); - } - // Check for service (any object with at least one service method) - if (_.some(this.methods, hasServiceMethod)) { - return this.service(location, service); + if(hasMethod('handle', 'set') || !hasMethod.apply(null, this.methods)) { + return this._super.apply(this, arguments); } - // Pass to the original express app - return this._super.apply(this, arguments); + return this.service(location, service); + }, lookup: function (location) {