YUKI Hiroshi
null+****@clear*****
Wed Jun 25 18:23:22 JST 2014
YUKI Hiroshi 2014-06-25 18:23:22 +0900 (Wed, 25 Jun 2014) New Revision: 63cd0ea3ddcd09dd13744884b4d01f12f303737b https://github.com/droonga/express-droonga/commit/63cd0ea3ddcd09dd13744884b4d01f12f303737b Message: Accept regexp as the path Modified files: lib/adapter/api/droonga.js lib/adapter/http.js Modified: lib/adapter/api/droonga.js (+4 -4) =================================================================== --- lib/adapter/api/droonga.js 2014-06-25 15:05:55 +0900 (ed2e041) +++ lib/adapter/api/droonga.js 2014-06-25 18:23:22 +0900 (de0a93c) @@ -3,9 +3,9 @@ var command = require('../command'); module.exports = { 'droonga-get': new command.HTTPRequestResponse({ method: 'GET', - path: '/droonga/:messageType', + path: /^\/droonga\/(.+)/, onRequest: function(request, connection) { - var messageType = request.params.messageType; + var messageType = request.params[0]; var body = {}; body.timeout = body.timeout || 1000; connection.emit(messageType, body); @@ -14,9 +14,9 @@ module.exports = { // XXX dangerous! this must be disabled on public services. 'droonga-post': new command.HTTPRequestResponse({ method: 'POST', - path: '/droonga/:messageType', + path: /^\/droonga\/(.+)/, onRequest: function(request, connection) { - var messageType = request.params.messageType; + var messageType = request.params[0]; var body = ''; request.on('data', function(chunk) { body += chunk; Modified: lib/adapter/http.js (+13 -1) =================================================================== --- lib/adapter/http.js 2014-06-25 15:05:55 +0900 (51326dc) +++ lib/adapter/http.js 2014-06-25 18:23:22 +0900 (bb88481) @@ -162,7 +162,19 @@ exports.register = function(application, params) { name: definition.command || commandName, definition: definition }); - application[method](prefix + definition.path, handler); + var path; + if (typeof definition.path == 'string') { + path = prefix + definition.path; + } else { // regexp + var flags = definition.path.ignoreCase ? 'i' : '' ; + var source = definition.path.source; + if (source.charAt(0) == '^') { + path = new RegExp('^' + prefix + source.replace(/^\^/, ''), flags); + } else { + path = new RegExp(prefix + source, flags); + } + } + application[method](path, handler); registeredCommands.push({ name: commandName, definition: definition, handler: handler }); -------------- next part -------------- HTML����������������������������...Download