get_tenant_from_req = (req, hostPartsOffset) => {
  if (req.subdomains && req.subdomains.length > 0)
    return req.subdomains[req.subdomains.length - 1];

  if (req.subdomains && req.subdomains.length == 0)
    return db.connectObj.default_schema;
  if (!req.subdomains && req.headers.host) {
    if (is_ip_address(req.headers.host.split(":")[0]))
      return db.connectObj.default_schema;
    const parts = req.headers.host.split(".");
    if (parts.length < (!hostPartsOffset ? 3 : 3 - hostPartsOffset))
      return db.connectObj.default_schema;
    else return parts[0];
  }
}
Tries to recognize tenant from HTTP Request
@param {object} req
@param {number|undefined} hostPartsOffset (optional) for socketIO, to get the tenant with localhost
@returns {string}