[Groonga-commit] groonga/express-droonga at cde7448 [master] Add groonga compatible API layer

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 22 00:17:56 JST 2013


Kouhei Sutou	2013-07-22 00:17:56 +0900 (Mon, 22 Jul 2013)

  New Revision: cde7448ff6a1121ee93bb71122a92976d2d5a279
  https://github.com/groonga/express-droonga/commit/cde7448ff6a1121ee93bb71122a92976d2d5a279

  Message:
    Add groonga compatible API layer
    
    Tests for the API layer should be written!!!

  Added files:
    lib/frontend/api/groonga.js
  Modified files:
    index.js

  Modified: index.js (+2 -0)
===================================================================
--- index.js    2013-07-21 22:45:32 +0900 (e74e526)
+++ index.js    2013-07-22 00:17:56 +0900 (f7aa269)
@@ -1,6 +1,7 @@
 var express = require('express');
 var Connection = require('./lib/backend/connection').Connection;
 var restAPI = require('./lib/frontend/api/rest');
+var groongaAPI = require('./lib/frontend/api/groonga');
 var socketIoAPI = require('./lib/frontend/api/socket.io');
 var dashboardUI = require('./lib/frontend/ui/dashboard');
 
@@ -14,6 +15,7 @@ express.application.droonga = function(params) {
   params.prefix = params.prefix.replace(/\/$/, '');
 
   restAPI.register(this, params);
+  groongaAPI.register(this, params);
 
   if (params.server) {
     socketIoAPI.register(this, params.server, params);

  Added: lib/frontend/api/groonga.js (+38 -0) 100644
===================================================================
--- /dev/null
+++ lib/frontend/api/groonga.js    2013-07-22 00:17:56 +0900 (22d1dd2)
@@ -0,0 +1,38 @@
+var debug = require('../../debug');
+var model = require('../../model');
+
+function handle(connection, request, response) {
+  debug('api.groonga.handle');
+
+  connection.emitMessage(
+    request.params.command,
+    request.query,
+    function(error, envelope) {
+      debug('api.groonga.handle.response');
+      if (error) {
+        debug('api.groonga.handle.response:', error);
+        var body = envelope && envelope.body || null;
+        response.jsonp(error, body);
+      } else {
+        debug('api.groonga.handle.success');
+        var body = envelope.body;
+        response.jsonp(body);
+      }
+    }
+  );
+}
+
+exports.register = function(application, params) {
+  params = params || {};
+  var connection = params.connection;
+  if (!connection)
+    throw new Error('Connection to the backend is required!');
+
+  var prefix = params.prefix || '';
+  prefix = prefix.replace(/\/$/, '');
+
+  application.get(prefix + '/d/:command', function(request, response) {
+    handle(connection, request, response);
+  });
+  // TODO: support load by POST
+}
-------------- next part --------------
HTML����������������������������...
Download 



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