<commit_before>import fetch from 'isomorphic-fetch'
import url from 'url'

import config from '../config'

export default class APIClient {
  
  constructor({ path, method, query, body }) {
    const apiUrlObject = new url.Url()

    delete apiUrlObject.search 

    apiUrlObject.pathname = path
    apiUrlObject.protocol = (this.isServer() ? 'http' : window.location.protocol)
    apiUrlObject.host = (this.isServer() ? `localhost:${config.PORT}`: `${window.location.host}:${window.location.port}`)
    
    if (query) {
      apiUrlObject.query = query
    }

    return new Promise((resolve, reject) => {
      fetch(url.format(apiUrlObject)). 
        then((res) => {
          return res.json()
        }).
        then((body) => {
          return resolve(body)
        }).
        catch((err) => {
          return reject(err)
        })
    })
  }

  isServer() {
    return ! (typeof window !== 'undefined' && window.document);
  }

}<commit_msg>Fix invalid hostname on browser<commit_after>import fetch from 'isomorphic-fetch'
import url from 'url'

import config from '../config'

export default class APIClient {
  
  constructor({ path, method, query, body }) {
    const apiUrlObject = new url.Url()

    apiUrlObject.pathname = path
    apiUrlObject.protocol = (this.isServer() ? 'http' : window.location.protocol)
    apiUrlObject.host = (this.isServer() ? `localhost:${config.PORT}`: `${window.location.host}`)
    
    if (query) {
      apiUrlObject.query = query
    }

    return new Promise((resolve, reject) => {
      fetch(decodeURI(url.format(apiUrlObject))). 
        then((res) => {
          return res.json()
        }).
        then((body) => {
          return resolve(body)
        }).
        catch((err) => {
          return reject(err)
        })
    })
  }

  isServer() {
    return ! (typeof window !== 'undefined' && window.document);
  }

}
{'fraction_non_alphanumeric': 0.14930924548352817, 'fraction_numerical': 0.0, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3357787', 'n_tokens_mistral': 569, 'n_tokens_neox': 562, 'n_words': 124}