Skip to content

Commit 5527a1e

Browse files
authored
Merge pull request #181 from github/fix-graphql-hostname
Explicitly check for subdomain isolation to make sure all URLs work
2 parents 1ead6f8 + f90f446 commit 5527a1e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

graphql/enterprise/index.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,25 @@ <h3>Create a <a href="https://help.github.com/articles/creating-a-personal-acces
170170
// as long as it returns a Promise or Observable.
171171
function graphQLFetcher(graphQLParams) {
172172
// Determine the API URL for this GitHub Enterprise server
173+
173174
const hostnames = location.hostname.split('.')
174-
const apiHost = location.protocol + '//' + hostnames[hostnames.length - 2] + '.' + hostnames[hostnames.length - 1]
175+
176+
const apiHost = function () {
177+
if (hostnames[0] === "pages") {
178+
// subdomain isolation enabled, so remove the first part of the URL
179+
hostnames.shift()
180+
return location.protocol + '//' + hostnames.join('.')
181+
} else {
182+
// no subdomain isolation
183+
return location.protocol + '//' + location.hostname
184+
}
185+
}()
186+
175187
return fetch(apiHost + '/api/graphql', {
176188
method: 'post',
177189
headers: {
178190
'Accept': 'application/json',
179-
'Authorization': 'Basic ' + authToken,
191+
'Authorization': 'Bearer ' + authToken,
180192
'Content-Type': 'application/json'
181193
},
182194
mode: 'cors',

0 commit comments

Comments
 (0)