Navigation Menu

Skip to content

Commit

Permalink
Accept regexp as the path
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 25, 2014
1 parent 19ba468 commit 63cd0ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/adapter/api/droonga.js
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion lib/adapter/http.js
Expand Up @@ -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 });
Expand Down

0 comments on commit 63cd0ea

Please sign in to comment.