Navigation Menu

Skip to content

Commit

Permalink
Accept specific hostname for Configuration API and Documents/batch, S…
Browse files Browse the repository at this point in the history
…earch API
  • Loading branch information
piroor committed Aug 15, 2012
1 parent f0f5b07 commit e81d99b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
18 changes: 15 additions & 3 deletions bin/gcs
Expand Up @@ -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() {
Expand Down
15 changes: 7 additions & 8 deletions lib/api/2011-02-01/configuration.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions lib/command-line.js
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions lib/server.js
@@ -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());
Expand Down

0 comments on commit e81d99b

Please sign in to comment.