Godaddy API Search

There's a CORS issue with this GoDaddy Search. Most likely because I'm attempting to use somebody else's `sso-key` and it's not correctly configured for my development environment.

by David Iglesias

HTML

<h1>
Godaddy search
</h1>

<input type="text" value="flutter.dev" id="domainName" />
<input type="button" id="search" value="search (fetch)" />
<input type="button" id="searchXhr" value="search (xhr)" />

<pre id="output"></pre>

JavaScript

const _apiUrl = 'https://api.ote-godaddy.com/v1/domains/available';
const _authToken = 'sso-key 3mM44UcgfE8M7d_SGrAhFrzGoTDkPKR3jLeWa:Sj2bjsqAWKsji28w8JEdZd';

async function xhrDomain(domain) {
	let url = `${_apiUrl}?domain=${domain}`;
  let request = new XMLHttpRequest();
  request.open('GET', url, false);
  // request.withCredentials = true;
	request.setRequestHeader('Authorization', _authToken);
  try {
    request.send();
  } catch(e) {
    return `${e}\n(More details in the JS Console)`;
  }
  return request.response;
}

async function fetchDomain(domain) {
	let url = `${_apiUrl}?domain=${domain}`;
  try {
    let response = await fetch(url, {
      // credentials: 'include',
      headers: {
        'Authorization': _authToken,
      },
    });
  } catch (e) {
    return `${e}\n(More details in the JS Console)`;
  }
  return response;
}

search.addEventListener('click', async function(event) {
  output.innerText = await fetchDomain(domainName.value);
});

searchXhr.addEventListener('click', async function(event) {
  output.innerText = await xhrDomain(domainName.value);
});