[Groonga-commit] groonga/express-kotoumi [master] Update REST adaptor for the new plugin model

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Feb 7 16:55:13 JST 2013


YUKI Hiroshi	2013-02-07 16:55:13 +0900 (Thu, 07 Feb 2013)

  New Revision: aa77c07aa9ed591d33aff55e5902013861f684c3
  https://github.com/groonga/express-kotoumi/commit/aa77c07aa9ed591d33aff55e5902013861f684c3

  Log:
    Update REST adaptor for the new plugin model

  Modified files:
    lib/frontend/rest-adaptor.js

  Modified: lib/frontend/rest-adaptor.js (+9 -11)
===================================================================
--- lib/frontend/rest-adaptor.js    2013-02-07 16:50:19 +0900 (ee50e83)
+++ lib/frontend/rest-adaptor.js    2013-02-07 16:55:13 +0900 (4eb8511)
@@ -5,14 +5,13 @@ function createHandler(params) {
   params = params || {};
   var connection = params.connection;
   var command = params.command;
-  var requestBuilder = params.requestBuilder;
-  var responseBuilder = params.responseBuilder;
+  var definition = params.definition;
 
-  if (!requestBuilder)
-    throw new Error('no request builder for ' + command);
+  if (!definition.toBackend)
+    throw new Error('no filter for the backend: ' + command);
 
   return (function(request, response) {
-    var message = requestBuilder(request);
+    var message = definition.toBackend(request);
     var timeout = message.timeout || null;
     connection.emitMessage(
       command,
@@ -24,8 +23,8 @@ function createHandler(params) {
           response.send(body, error);
         } else {
           var body = responseMessage.body;
-          if (responseBuilder)
-            body = responseBuilder(body);
+          if (definition.toClient)
+            body = definition.toClient(body);
           response.contentType('application/json');
           response.send(body, 200);
         }
@@ -74,10 +73,9 @@ exports.register = function(application, params) {
       return;
     var method = getRegisterationMethod(definition.method);
     var handler = createHandler({
-      connection:      connection,
-      command:         definition.command || command,
-      requestBuilder:  definition.requestBuilder,
-      responseBuilder: definition.responseBuilder
+      connection: connection,
+      command:    definition.command || command,
+      definition: definition
     });
     application[method](prefix + definition.path, handler);
     registeredCommands.push({ command:    command,
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index