Kouhei Sutou
null+****@clear*****
Mon Jul 22 23:31:47 JST 2013
Kouhei Sutou 2013-07-22 23:31:47 +0900 (Mon, 22 Jul 2013) New Revision: f1023265e30ce8ba89f35d177c3029d0e8f205ca https://github.com/groonga/express-droonga/commit/f1023265e30ce8ba89f35d177c3029d0e8f205ca Message: Implement groonga API on the http adapter Added files: lib/adapter/api/groonga.js Removed files: lib/adapter/groonga.js Modified files: index.js lib/adapter/http.js test/adapter/rest.test.js Modified: index.js (+0 -2) =================================================================== --- index.js 2013-07-22 23:21:29 +0900 (d043ef6) +++ index.js 2013-07-22 23:31:47 +0900 (8e02d04) @@ -1,7 +1,6 @@ var express = require('express'); var Connection = require('./lib/backend/connection').Connection; var httpAdapter = require('./lib/adapter/http'); -var groongaAdapter = require('./lib/adapter/groonga'); var socketIoAdapter = require('./lib/adapter/socket.io'); var dashboardUI = require('./lib/ui/dashboard'); @@ -15,7 +14,6 @@ express.application.droonga = function(params) { params.prefix = params.prefix.replace(/\/$/, ''); httpAdapter.register(this, params); - groongaAdapter.register(this, params); if (params.server) { socketIoAdapter.register(this, params.server, params); Added: lib/adapter/api/groonga.js (+10 -0) 100644 =================================================================== --- /dev/null +++ lib/adapter/api/groonga.js 2013-07-22 23:31:47 +0900 (247f20a) @@ -0,0 +1,10 @@ +var model = require('../../model'); + +module.exports = { + 'groonga': new model.HTTPCommand({ + path: '/d/:commandName', + toBackend: function(commandName, request) { + return [request.params.commandName, request.query]; + } + }) +}; Deleted: lib/adapter/groonga.js (+0 -38) 100644 =================================================================== --- lib/adapter/groonga.js 2013-07-22 23:21:29 +0900 (b37f07c) +++ /dev/null @@ -1,38 +0,0 @@ -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 -} Modified: lib/adapter/http.js (+2 -1) =================================================================== --- lib/adapter/http.js 2013-07-22 23:21:29 +0900 (a2415d7) +++ lib/adapter/http.js 2013-07-22 23:31:47 +0900 (810f130) @@ -2,6 +2,7 @@ var debug = require('../debug'); var model = require('../model'); var restAPI = require('./api/rest'); +var groongaAPI = require('./api/groonga'); function createHandler(params) { params = params || {}; @@ -65,7 +66,7 @@ exports.register = function(application, params) { var prefix = params.prefix || ''; prefix = prefix.replace(/\/$/, ''); - var commandSets = [restAPI].concat(params.plugins || []); + var commandSets = [restAPI, groongaAPI].concat(params.plugins || []); var unifiedCommandSet = {}; commandSets.forEach(function(commandSet) { Object.keys(commandSet).forEach(function(commandName) { Modified: test/adapter/rest.test.js (+3 -0) =================================================================== --- test/adapter/rest.test.js 2013-07-22 23:21:29 +0900 (1e93d17) +++ test/adapter/rest.test.js 2013-07-22 23:31:47 +0900 (a33ec70) @@ -8,6 +8,7 @@ var express = require('express'); var httpAdapter = require('../../lib/adapter/http'); var model = require('../../lib/model'); var restAPI = require('../../lib/adapter/api/rest'); +var groongaAPI = require('../../lib/adapter/api/groonga'); suite('HTTP Adapter', function() { test('registeration of plugin commands', function() { @@ -59,6 +60,8 @@ suite('HTTP Adapter', function() { assert.deepEqual(registeredCommands, [{ name: 'search', definition: restAPI.search }, + { name: 'groonga', + definition: groongaAPI.groonga }, { name: 'getCommand', definition: basePlugin.getCommand }, { name: 'putCommand', -------------- next part -------------- HTML����������������������������... Download