This repository was archived by the owner on Jan 10, 2024. It is now read-only.
This repository was archived by the owner on Jan 10, 2024. It is now read-only.
forcetk.Client constructor builds incorrect instanceUrl when running on na1.salesforce.com #4
Closed

Description
Current code fails to take into account VF hosts such as na1.salesforce.com:
// location.hostname is of the form 'abc.na1.visual.force.com', so we
// can simply split it on '.' and take the second element of the
// resulting array
this.instance_url = "https://" + location.hostname.split(".")[1]
+ ".salesforce.com";
As a result, it erroneously builds an instanceUrl such as salesforce.salesforce.com. Since there is no way to directly get the instance component or the whole URL in Visualforce, an acceptable heuristic would be to look at the number of elements in the hostname and choose the first or second as appropriate:
// location.hostname can be of the form 'abc.na1.visual.force.com' or
// 'na1.salesforce.com'. Split on '.', and take the [1] or [0] element
// as appropriate
var elements = location.hostname.split(".");
var instance = (elements.length == 3) ? elements[0] : elements[1];
this.instance_url = "https://"+instance+".salesforce.com";
Many thanks to @jeffdonthemic for the bug report!
Metadata
Metadata
Assignees
Labels
No labels