YUKI Hiroshi
null+****@clear*****
Thu Jan 9 16:52:45 JST 2014
YUKI Hiroshi 2014-01-09 16:52:45 +0900 (Thu, 09 Jan 2014) New Revision: c340b694ac88b15070a65af3afa1d57970c434fa https://github.com/droonga/express-droonga/commit/c340b694ac88b15070a65af3afa1d57970c434fa Message: Use given "onHandle" correctly Modified files: lib/adapter/command.js lib/adapter/http.js Modified: lib/adapter/command.js (+8 -0) =================================================================== --- lib/adapter/command.js 2014-01-09 12:46:22 +0900 (4ed051f) +++ lib/adapter/command.js 2014-01-09 16:52:45 +0900 (c3161b3) @@ -112,6 +112,14 @@ HTTPCommand.extend = function(targetClass) { Object.defineProperty(targetClass.prototype, 'method', { get: function() { return this._options.method || 'GET'; } }); + + Object.defineProperty(targetClass.prototype, 'onHandle', { + get: function() { + if (!this._options.onHandle) + throw new Error('onHandle() is missing'); + return this._options.onHandle + } + }); }; HTTPCommand.extend(HTTPCommand); exports.HTTPCommand = HTTPCommand; Modified: lib/adapter/http.js (+2 -3) =================================================================== --- lib/adapter/http.js 2014-01-09 12:46:22 +0900 (9cb5993) +++ lib/adapter/http.js 2014-01-09 16:52:45 +0900 (fffd97b) @@ -38,7 +38,7 @@ function createRequestResponseHandler(params) { var wrappedConnection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, options); if (definition.onRequest) { try { - definition.onRequest(request, wrappedConnection); + definition.onRequest(request, wrappedConnection, response); } catch(error) { wrappedConnection.destroy(); response.jsonp(error, 500); @@ -120,8 +120,7 @@ exports.register = function(application, params) { if (command.RequestResponse.isInstance(definition)) { creator = createRequestResponseHandler; } else { - if (typeof definition.onHandle != 'function') - throw new Error('onHandle() is missing'); + definition.onHandle; // try to get it. if it is undefined, the definition raises error. creator = createGenericHandler; } -------------- next part -------------- HTML����������������������������...Download