API Server

The APIServer function generates a hostname for the API server by adding 'api-' to the current domain name after removing the prefix 'www.', if present. If SSL is being used, the returned port is 8443; other 8080.

APIServer = Resolve;

function Resolve()
{
    var base_domain = Resolve.ExtractBaseDomain( location.hostname );
	var dom = "";

	switch ( location.protocol )
	{
	case "http:":
		dom = location.protocol + "//api-" + base_domain + ":8080";
		break;

	case "https:":
		dom = location.protocol + "//api-" + base_domain + ":8443";
		break;
	}

	return dom;
}

Resolve.ExtractBaseDomain
=
function( domain )
{
	var base_domain = "";
	var bits = domain.split( "-" );
	
	if ( 1 == bits.length )
	{
		base_domain = bits[0];
	}
	else
	{
		base_domain = bits[1];
	}
	return base_domain;
}