Navigation Menu

Skip to content

Commit

Permalink
Fixup IP address to valid hostname (with xip.io)
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 22, 2012
1 parent e227ae4 commit 15856fa
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/database/domain.js
Expand Up @@ -49,6 +49,15 @@ function assertValidDomainName(domain) {
}
}

function toValidHostAndPort(hostAndPort) {
hostAndPort = hostAndPort.split(':');
if (hostAndPort[0] == 'localhost')
hostAndPort[0] = '127.0.0.1';
if (hostAndPort[0].match(/^\d+\.\d+\.\d+\.\d+$/))
hostAndPort[0] += '.xip.io';
return hostAndPort.join(':');
}

// Accepts two arguments: source and context.
// You can give them in the reversed order, like:
// new Domain("source", context) or new Domain(context, "source")
Expand Down Expand Up @@ -251,14 +260,14 @@ Domain.prototype = {
},

getDocumentsEndpoint: function(hostname) {
if (hostname[0] != '.')
hostname = '.' + hostname;
return 'doc-' + this.name + '-' + this.id + hostname;
hostanme = hostname.replace(/^\./, '');
hostname = toValidHostAndPort(hostname);
return 'doc-' + this.name + '-' + this.id + '.' + hostname;
},
getSearchEndpoint: function(hostname) {
if (hostname[0] != '.')
hostname = '.' + hostname;
return 'search-' + this.name + '-' + this.id + hostname;
hostanme = hostname.replace(/^\./, '');
hostname = toValidHostAndPort(hostname);
return 'search-' + this.name + '-' + this.id + '.' + hostname;
},

createSync: function() {
Expand Down

0 comments on commit 15856fa

Please sign in to comment.