lib/app.js
function registerCors(app, corsConfig, corsIgnore) {
    if (corsConfig === false) return;
    let domains = [];
    if (typeof corsConfig === 'string') {
      domains = corsConfig.split(' ');
    } else if (corsConfig instanceof Array) {
      domains = corsConfig;
    }
    app.use((req, res, next) => {
      let origin = req.headers['origin'] || req.headers['referer'] || null,
        shouldAddHeaders = false,
        rawOrigin = origin;
      if(typeof rawOrigin === 'string') {
        let qsIdx= rawOrigin.indexOf('?');
        if(qsIdx !== -1) {
          rawOrigin = rawOrigin.substr(0, qsIdx);
        }
      }
      if (corsConfig === true) {
        shouldAddHeaders = true;
      } else if (domains.length > 0 && typeof origin === 'string') {
        origin = getRawOrigin(origin);
        for (let i = 0; i < domains.length; i++) {
          let domain = domains[i],
            isMatch = matchCorsOrigin(domain, origin, rawOrigin);
          if (isMatch) {
            shouldAddHeaders = true;
            break;
          }
        }
      }
      if (!shouldAddHeaders) return next();
      // CHECK if we have corsIgnore in settings
      let ignoreHosts;
      if (typeof corsIgnore === 'string') {
        ignoreHosts = [corsIgnore];
      } else if (corsIgnore instanceof Array) {
        ignoreHosts = corsIgnore;
      }
      if (ignoreHosts instanceof Array) {
        origin = getRawOrigin(origin);
        for (let i = 0; i < ignoreHosts.length; i++) {
          let domain = ignoreHosts[i],
            isMatch = matchCorsOrigin(domain, origin, rawOrigin);
          if (isMatch) return next;
        }
      }
      res.header('Access-Control-Allow-Origin', rawOrigin || '*');
      res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
      res.header('Access-Control-Allow-Credentials', 'true');
      res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers'] || '*');
      res.header('Access-Control-Max-Age', '600');
      next();
    });
  }
function registerCors(app, corsConfig, corsIgnore) {
    if (corsConfig === false) return;
    let domains = [];
    if (typeof corsConfig === 'string') {
      domains = corsConfig.split(' ');
    } else if (corsConfig instanceof Array) {
      domains = corsConfig;
    }
    app.use((req, res, next) => {
      let origin = req.headers['origin'] || req.headers['referer'] || null,
        shouldAddHeaders = false,
        rawOrigin = origin;
      if(typeof rawOrigin === 'string') {
        let qsIdx= rawOrigin.indexOf('?');
        if(qsIdx !== -1) {
          rawOrigin = rawOrigin.substr(0, qsIdx);
        }
      }
      if (corsConfig === true) {
        shouldAddHeaders = true;
      } else if (domains.length > 0 && typeof origin === 'string') {
        origin = getRawOrigin(origin);
        for (let i = 0; i < domains.length; i++) {
          let domain = domains[i],
            isMatch = matchCorsOrigin(domain, origin, rawOrigin);
          if (isMatch) {
            shouldAddHeaders = true;
            break;
          }
        }
      }
      if (!shouldAddHeaders) return next();
      // CHECK if we have corsIgnore in settings
      let ignoreHosts;
      if (typeof corsIgnore === 'string') {
        ignoreHosts = [corsIgnore];
      } else if (corsIgnore instanceof Array) {
        ignoreHosts = corsIgnore;
      }
      if (ignoreHosts instanceof Array) {
        origin = getRawOrigin(origin);
        for (let i = 0; i < ignoreHosts.length; i++) {
          let domain = ignoreHosts[i],
            isMatch = matchCorsOrigin(domain, origin, rawOrigin);
          if (isMatch) return next;
        }
      }
      res.header('Access-Control-Allow-Origin', rawOrigin || '*');
      res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
      res.header('Access-Control-Allow-Credentials', 'true');
      res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers'] || '*');
      res.header('Access-Control-Max-Age', '600');
      next();
    });
  }
/*
Checks if we have CORS handling for the app.