[Groonga-commit] groonga/gcs [master] Accept specific hostname for Configuration API and Documents/batch, Search API

Back to archive index

SHIMODA Hiroshi null+****@clear*****
Wed Aug 15 15:16:22 JST 2012


SHIMODA Hiroshi	2012-08-15 15:16:22 +0900 (Wed, 15 Aug 2012)

  New Revision: e81d99bc260a19359849b1471ad3842d5f39547a
  https://github.com/groonga/gcs/commit/e81d99bc260a19359849b1471ad3842d5f39547a

  Log:
    Accept specific hostname for Configuration API and Documents/batch, Search API

  Modified files:
    bin/gcs
    lib/api/2011-02-01/configuration.js
    lib/command-line.js
    lib/server.js

  Modified: bin/gcs (+15 -3)
===================================================================
--- bin/gcs    2012-08-15 15:36:05 +0900 (f0cf489)
+++ bin/gcs    2012-08-15 15:16:22 +0900 (7942333)
@@ -14,12 +14,24 @@ commandLine
             '[' + CLI.defaultPrivilegedRanges + ']',
           String,
           CLI.defaultPrivilegedRanges)
+  .option('--base-host <hostname>',
+          'The base host name assigned to this server '+
+            '[' + CLI.defaultBaseHost + ']',
+          String,
+          CLI.defaultBaseHost)
+  .option('--configuration-host <hostname>',
+          'The host name for configuration API of this server '+
+            '[' + CLI.defaultConfigurationHost + ']',
+          String,
+          CLI.defaultConfigurationHost)
   .parse();
 
 var server = gcsServer.createServer({
-      databasePath:     commandLine.options.databasePath,
-      privilegedRanges: commandLine.options.privilege,
-      port:             commandLine.options.port
+      databasePath:      commandLine.options.databasePath,
+      privilegedRanges:  commandLine.options.privilege,
+      port:              commandLine.options.port,
+      baseHost:          commandLine.options.baseHost,
+      configurationHost: commandLine.options.configurationHost
     });
 
 server.listen(commandLine.options.port, function() {

  Modified: lib/api/2011-02-01/configuration.js (+7 -8)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-08-15 15:36:05 +0900 (43dc7b5)
+++ lib/api/2011-02-01/configuration.js    2012-08-15 15:16:22 +0900 (a1ee048)
@@ -25,13 +25,12 @@ function createCommonErrorResponse(errorCode, error) {
 var handlers = Object.create(null);
 
 
-function getBaseHostAndPort(request, config) {
-  var host = request.headers.host;
-  var baseHost = host.replace(/^cloudsearch\./, '');
+function getBaseHostAndPort(config) {
+  var host = config.configurationHost;
   if (config.port == 80)
-    return baseHost;
+    return host;
   else
-    return baseHost + ':' + config.port;
+    return host + ':' + config.port;
 }
 
 function createDomainStatus(options) {
@@ -84,7 +83,7 @@ handlers.CreateDomain = function(context, request, response, config) {
     response.contentType('application/xml');
     response.send(createCreateDomainResponse({
       domain:      domain,
-      hostAndPort: getBaseHostAndPort(request, config),
+      hostAndPort: getBaseHostAndPort(config),
       created:     true
     }));
   } catch (error) {
@@ -114,7 +113,7 @@ handlers.DeleteDomain = function(context, request, response, config) {
     response.contentType('application/xml');
     response.send(createDeleteDomainResponse({
       domain:      domain,
-      hostAndPort: getBaseHostAndPort(request, config),
+      hostAndPort: getBaseHostAndPort(config),
       deleted:     true
     }));
   } catch (error) {
@@ -167,7 +166,7 @@ handlers.DescribeDomains = function(context, request, response, config) {
     response.contentType('application/xml');
     response.send(createDescribeDomainsResponse({
       domains:     domains,
-      hostAndPort: getBaseHostAndPort(request, config)
+      hostAndPort: getBaseHostAndPort(config)
     }));
   } catch (error) {
     var body = createCommonErrorResponse('InternalFailure',

  Modified: lib/command-line.js (+6 -0)
===================================================================
--- lib/command-line.js    2012-08-15 15:36:05 +0900 (89aab4c)
+++ lib/command-line.js    2012-08-15 15:16:22 +0900 (41bf7eb)
@@ -10,6 +10,12 @@ var defaultDatabasePath =
 var defaultPort =
       exports.defaultPort =
       CommandLineInterface.defaultPort = 7575;
+var defaultBaseHostt =
+      exports.defaultBaseHostt =
+      CommandLineInterface.defaultBaseHostt = '127.0.0.1.xip.io';
+var defaultConfigurationHostt =
+      exports.defaultConfigurationHostt =
+      CommandLineInterface.defaultConfigurationHostt = '127.0.0.1.xip.io';
 var defaultPrivilegedRanges =
       exports.defaultPrivilegedRanges =
       CommandLineInterface.defaultPrivilegedRanges = '127.0.0.0/8';

  Modified: lib/server.js (+8 -0)
===================================================================
--- lib/server.js    2012-08-15 15:36:05 +0900 (3cf291e)
+++ lib/server.js    2012-08-15 15:16:22 +0900 (d8b3f26)
@@ -1,9 +1,17 @@
 var express = require('express');
 var nroonga = require('./wrapped-nroonga');
+var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface;
 var api = require('./api');
 var dashboard = require('./dashboard');
 
 exports.createServer = function (config) {
+  if (!config.databasePath) config.databasePath = CLI.databasePath;
+  if (!config.privilege)    config.privilege    = CLI.privilege;
+  if (!config.port)         config.port         = CLI.port;
+  if (!config.baseEndpoint) config.baseEndpoint = CLI.defaultBaseEndpoint;
+  if (!config.configurationEndpoint)
+     config.configurationEndpoint = CLI.defaultConfigurationEndpoint;
+
   var context = config.context || new nroonga.Context(config.databasePath);
   var application = express.createServer();
   application.use(express.bodyParser());
-------------- next part --------------
HTML����������������������������...
Download 



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