YUKI Hiroshi
null+****@clear*****
Fri Dec 28 18:07:28 JST 2012
YUKI Hiroshi 2012-12-28 18:07:28 +0900 (Fri, 28 Dec 2012) New Revision: d37ec8cb0cb59a32256ac16c9ec202e5059012e6 https://github.com/groonga/express-kotoumi/commit/d37ec8cb0cb59a32256ac16c9ec202e5059012e6 Log: Define default ports Modified files: lib/backend-adaptor.js test/backend-adaptor.test.js Modified: lib/backend-adaptor.js (+15 -14) =================================================================== --- lib/backend-adaptor.js 2012-12-28 17:55:13 +0900 (c1f26ed) +++ lib/backend-adaptor.js 2012-12-28 18:07:28 +0900 (3c56ec6) @@ -1,7 +1,8 @@ /** - * var connection = new Connection({ tag: 'groonga', - * host: 'localhost', - * port: 24224 }); + * var connection = new Connection({ tag: 'groonga', + * host: 'localhost', + * port: 24224, + * listenPort: 10030 }); * * // for REST APIs * connection.emitMessage( @@ -19,12 +20,16 @@ */ var EventEmitter = require('events').EventEmitter; -var http = require('http'); var socketIo = require('socket.io'); var fluent = require('fluent-logger'); +var DEFAULT_FLUENT_TAG = 'groonga'; +var DEFAULT_FLUENT_HOST = 'localhost'; +var DEFAULT_FLUENT_PORT = 24224; +var DEFAULT_LISTEN_PORT = 10030; + function Connection(params) { - this._params = params; + this._params = params || {}; this._init(); } @@ -35,24 +40,20 @@ Connection.prototype._init = function() { this._sender = ( this._params.sender || - fluent.createFluentSender(this._params.tag, - { host: this._params.host, - port: this._params.port }) + fluent.createFluentSender(this._params.tag || DEFAULT_FLUENT_TAG, + { host: this._params.host || DEFAULT_FLUENT_HOST, + port: this._params.port || DEFAULT_FLUENT_PORT }) ); - this._server = http.createServer(this._handleHttpRequest.bind(this)); - this._socket = socketIo.listen(this._server); + this._socket = socketIo.listen(this._params.listenPort || DEFAULT_LISTEN_PORT); var self = this; this._socket.sockets.on('connection', function(socket) { - socket.on(self._params.tag + '.message', + socket.on((self._params.tag || DEFAULT_FLUENT_TAG)+ '.message', self._handleMessage.bind(self)); }); this._socket.set('log level', 1); }; -Connection.prototype._handleHttpRequest = function(request, response) { -}; - Connection.prototype._handleMessage = function(message) { var replyTo = message['reply_to']; if (replyTo) { Modified: test/backend-adaptor.test.js (+3 -4) =================================================================== --- test/backend-adaptor.test.js 2012-12-28 17:55:13 +0900 (62d2b4a) +++ test/backend-adaptor.test.js 2012-12-28 18:07:28 +0900 (63113a5) @@ -15,10 +15,9 @@ suit('Connection', function() { } }; connection = new Connection({ - tag: 'test', - host: 'localhost', - port: 3000, - sender: sender + tag: 'test', + listenPort: 3333, + sender: sender }); }); -------------- next part -------------- HTML����������������������������... Download