function checkFunction(url, requestID) {
  const protocol = URL.parse(url).protocol;
  const hostname = URL.parse(url).hostname;
  const port     = URL.parse(url).port;

  const checks  = this.checks;
  const timeout = this.timeout;

  // Given a relative URL in string form, returns a parsed URL
  // which points to the local server's IP address and port
  // and has the right hostname property to use in the Host header.
  function loopbackResolve(relativeURL) {
    const absoluteURL = URL.parse(URL.resolve(`${protocol}//localhost/`, relativeURL));
    const loopbackURL = Object.assign({}, absoluteURL, {
      hostname: absoluteURL.hostname,
      host:     hostname,
      port:     port
    });
    return loopbackURL;
  }

  // Each check resolves into an outcome object
  const allChecks = Object.keys(checks).map(function(checkURL) {
    const expected = checks[checkURL];

    // We need to make an HTTP/S request to the current server,
    // based on the hostname/port passed to us,
    // so the HTTP check would go to http://localhost:80/ or some such URL.
    const headers = {
      'User-Agent':   'Mozilla/5.0 (compatible) Healthchecks http://broadly.com',
      'X-Request-Id': requestID || ''
    };

    const start = process.hrtime();
    return runCheck({ url: checkURL, headers, resolver: loopbackResolve, timeout })
      .then(function(response) {
        const elapsed = process.hrtime(start);
        const outcome = new Outcome({ url: checkURL, expected, statusCode: response.statusCode, body: response.body, elapsed });
        return outcome;
      })
      .catch(function(error) {
        const elapsed = process.hrtime(start);
        const outcome = new Outcome({ url: checkURL, expected, error, elapsed });
        return outcome;
      });
  });


  // Run all checks in parallel
  const allOutcomes = Promise.all(allChecks);

  // Reduce into an object with the passed and failed lists of URLs
  const passedAndFailed = allOutcomes
    .then(function(outcomes) {
      return {
        passed: outcomes.filter(outcome => !outcome.reason ),
        failed: outcomes.filter(outcome => outcome.reason )
      };
    });

  // Returns the promise
  return passedAndFailed;
}
// failed  - A list of all check URLs that failed
failed  - A list of all check URLs that failed
failed - A list of all check URLs that failed
function checkFunction(url, requestID) {
  const protocol = URL.parse(url).protocol;
  const hostname = URL.parse(url).hostname;
  const port     = URL.parse(url).port;
  const checks  = this.checks;
  const timeout = this.timeout;
  function loopbackResolve(relativeURL) {
    const absoluteURL = URL.parse(URL.resolve(`${protocol}//localhost/`, relativeURL));
    const loopbackURL = Object.assign({}, absoluteURL, {
      hostname: absoluteURL.hostname,
      host:     hostname,
      port:     port
    });
    return loopbackURL;
  }
  const allChecks = Object.keys(checks).map(function(checkURL) {
    const expected = checks[checkURL];
    const headers = {
      'User-Agent':   'Mozilla/5.0 (compatible) Healthchecks http://broadly.com',
      'X-Request-Id': requestID || ''
    };
    const start = process.hrtime();
    return runCheck({ url: checkURL, headers, resolver: loopbackResolve, timeout })
      .then(function(response) {
        const elapsed = process.hrtime(start);
        const outcome = new Outcome({ url: checkURL, expected, statusCode: response.statusCode, body: response.body, elapsed });
        return outcome;
      })
      .catch(function(error) {
        const elapsed = process.hrtime(start);
        const outcome = new Outcome({ url: checkURL, expected, error, elapsed });
        return outcome;
      });
  });
  const allOutcomes = Promise.all(allChecks);
  const passedAndFailed = allOutcomes
    .then(function(outcomes) {
      return {
        passed: outcomes.filter(outcome => !outcome.reason ),
        failed: outcomes.filter(outcome => outcome.reason )
      };
    });
  return passedAndFailed;
}
function checkFunction ( url , requestID ) { const protocol = URL . parse ( url ) . protocol ; const hostname = URL . parse ( url ) . hostname ; const port = URL . parse ( url ) . port ; const checks = this . checks ; const timeout = this . timeout ; function loopbackResolve ( relativeURL ) { const absoluteURL = URL . parse ( URL . resolve ( ` ${ protocol } ` , relativeURL ) ) ; const loopbackURL = Object . assign ( { } , absoluteURL , { hostname : absoluteURL . hostname , host : hostname , port : port } ) ; return loopbackURL ; } const allChecks = Object . keys ( checks ) . map ( function ( checkURL ) { const expected = checks [ checkURL ] ; const headers = { 'User-Agent' : 'Mozilla/5.0 (compatible) Healthchecks http://broadly.com' , 'X-Request-Id' : requestID || '' } ; const start = process . hrtime ( ) ; return runCheck ( { url : checkURL , headers , resolver : loopbackResolve , timeout } ) . then ( function ( response ) { const elapsed = process . hrtime ( start ) ; const outcome = new Outcome ( { url : checkURL , expected , statusCode : response . statusCode , body : response . body , elapsed } ) ; return outcome ; } ) . catch ( function ( error ) { const elapsed = process . hrtime ( start ) ; const outcome = new Outcome ( { url : checkURL , expected , error , elapsed } ) ; return outcome ; } ) ; } ) ; const allOutcomes = Promise . all ( allChecks ) ; const passedAndFailed = allOutcomes . then ( function ( outcomes ) { return { passed : outcomes . filter ( outcome => ! outcome . reason ) , failed : outcomes . filter ( outcome => outcome . reason ) } ; } ) ; return passedAndFailed ; }
failed  - A list of all check URLs that failed
failed - A list of all check URLs that failed
// Given a relative URL in string form, returns a parsed URL // which points to the local server's IP address and port // and has the right hostname property to use in the Host header. // Each check resolves into an outcome object // We need to make an HTTP/S request to the current server, // based on the hostname/port passed to us, // so the HTTP check would go to http://localhost:80/ or some such URL. // Run all checks in parallel // Reduce into an object with the passed and failed lists of URLs // Returns the promise