const {send} = require('micro');
const fetch = require('node-fetch');
const assert = require('http-assert');

module.exports = async (req, res) => {
  let url = req.url.substr(1).split('?')[0];
  if (url === 'favicon.ico') return;
  if (url.indexOf('http://') !== -1) {
    url = url.substr(7);
  } else if (url.indexOf('https://') !== -1) {
    url = url.substr(8);
  }
  let json = req.url.indexOf('?json') !== -1;
  assert(url !== '', 400, 'URL must be defined. Usage: https://up.now.sh/google.com');
  let statusCode;
  let message;
  res.setHeader('Content-Type', 'application/json');
  try {
    await fetch(`http://${url}`, {
      timeout: 5000
    });
    statusCode = 200;
    if (json) {
      message = {url: url, status: 'Up'};
    } else {
      res.setHeader('Content-Type', 'text/plain');
      message = `${url} is up.`;
    }
  } catch (err) {
    const {type, code} = err;
    if (type === 'system' && code === 'ENOTFOUND') {
      statusCode = 200;
      message = (json) ? ({url: url, status: 'Down'}) : (`${url} is not up.`);
    } else {
      statusCode = 400;
      message = (json) ? ({error: 'Something went wrong.'}) : (`Something went wrong.`);
    }
  }
  send(res, statusCode, message);
};

@@ -230,31 +230,34 @@
 ;%0A  if (url.
-indexOf
+startsWith
 ('http://') 
@@ -251,31 +251,24 @@
 h('http://')
- !== -1
 ) %7B%0A    url 
@@ -301,23 +301,26 @@
 if (url.
-indexOf
+startsWith
 ('https:
@@ -323,23 +323,16 @@
 tps://')
- !== -1
 ) %7B%0A    

Use startsWith instead of indexOf when checking URL scheme