From ceb625242d53f52680021fa619fd7f104e091722 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 24 Jan 2009 12:27:15 +0000 Subject: Guess port based on protocol if we run on standard ports and in the browser. Closes COUCHDB-213. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@737346 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch_tests.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'share') diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index c87e01a5..01f94927 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -11,8 +11,13 @@ // the License. // Used by replication test -CouchDB.host = (typeof window == 'undefined' || !window) ? - "127.0.0.1:5984" : window.location.host; +if (typeof window == 'undefined' || !window) { + CouchDB.host = "127.0.0.1:5984"; + CouchDB.inBrowser = false; +} else { + CouchDB.host = window.location.host; + CouchDB.inBrowser = true; +} var tests = { @@ -2843,9 +2848,32 @@ var tests = { // test that /_config returns all the settings var xhr = CouchDB.request("GET", "/_config"); var config = JSON.parse(xhr.responseText); - var port = CouchDB.host.split(':').pop() + + /* + if we run on standard ports, we can't extract + the number from the URL. Instead we try to guess + from the protocol what port we are running on. + If we can't guess, we don't test for the port. + Overengineering FTW. + */ + var server_port = CouchDB.host.split(':'); + if(server_port.length == 1 && CouchDB.inBrowser) { + var proto = window.location.protocol; + if(proto == "http:") { + port = 80; + } + if(proto == "https:") { + port = 443; + } + } else { + port = server_port.pop(); + } + + if(port) { + T(config.httpd.port == port); + } + T(config.couchdb.database_dir); - T(config.httpd.port == port); T(config.daemons.httpd); T(config.httpd_global_handlers._config); T(config.log.level); -- cgit v1.2.3