zz_

index.js

thoward37@gmail.com/push-test3-1791933214491 / index.js @ 8f9f8fa1 Download
Ladder Summary
  • file The module exports a single **default async function `isUp(url)`** that checks whether a given website is reachable. It extracts the hostname from the provided URL, queries the `https://isitup.org/<hostname>.json` API via `got`, throws an error if the API reports an invalid domain, and otherwise returns `true` when the site’s status code indicates it is up (and `false` when it is down).
 'use strict';
 var got = require('got');
 
 module.exports = function (url, cb) {
  got('http://isitup.org/' + url + '.json', {
  headers: {
  'user-agent': 'https://github.com/sindresorhus/is-up'
  }
  }, function (err, res) {
  if (err) {
  cb(err);
  return;
  }
 
  res = JSON.parse(res);
 
  if (res.status_code === 3) {
  cb(new Error('Invalid domain'));
  return;
  }
 
  cb(null, res.status_code === 1);
  });
 };