<commit_before>const _ = require('underscore');
const habitat = require('habitat');
const env = new habitat('openbadger');
const urlutil = require('url');

// In here we hack the environment variables that habitat uses based on
// VCAP_SERVICES provided by CloudFoundry
require('./cloudfoundry-env');

// just in case the old name of `persona_audience` is still being used
env.set('origin', env.get('origin', env.get('persona_audience')));

env.qualifyUrl = function qualifyUrl(path) {
  const pathParts = urlutil.parse(path);
  const urlParts = urlutil.parse(env.get('origin'));
  return urlutil.format(_.defaults(pathParts, urlParts));
};

env.origin = function origin() {
  return env.get('origin');
};

env.isAdmin = function isAdmin(email) {
  const admins = env.get('admins');
  return admins.some(function (admin) {
    return new RegExp(admin.replace('*', '.+?')).test(email);
  });
};

env.isHttps = function isHttps() {
  return /^https/.test(env.get('origin'));
};

env.emailCreds = function emailCreds() {
  const creds = {};
  creds.user = env.get('sendgrid_user');
  creds.pw = env.get('sendgrid_pw');
  return creds;
};

env.fullUrl = function fullUrl(pathname) {    
  if (env.get('env') == "localhost") {
      host = urlutil.format({
      protocol: env.get('protocol'),
      hostname: env.get('host'),
      port: env.get('port')
    });
  }
  else {
      host = urlutil.format({
      protocol: env.get('protocol'),
      hostname: env.get('host')
    });
  }

  return urlutil.resolve(host, pathname);
};

module.exports = env;<commit_msg>using env host for url utility conditional<commit_after>const _ = require('underscore');
const habitat = require('habitat');
const env = new habitat('openbadger');
const urlutil = require('url');

// In here we hack the environment variables that habitat uses based on
// VCAP_SERVICES provided by CloudFoundry
require('./cloudfoundry-env');

// just in case the old name of `persona_audience` is still being used
env.set('origin', env.get('origin', env.get('persona_audience')));

env.qualifyUrl = function qualifyUrl(path) {
  const pathParts = urlutil.parse(path);
  const urlParts = urlutil.parse(env.get('origin'));
  return urlutil.format(_.defaults(pathParts, urlParts));
};

env.origin = function origin() {
  return env.get('origin');
};

env.isAdmin = function isAdmin(email) {
  const admins = env.get('admins');
  return admins.some(function (admin) {
    return new RegExp(admin.replace('*', '.+?')).test(email);
  });
};

env.isHttps = function isHttps() {
  return /^https/.test(env.get('origin'));
};

env.emailCreds = function emailCreds() {
  const creds = {};
  creds.user = env.get('sendgrid_user');
  creds.pw = env.get('sendgrid_pw');
  return creds;
};

env.fullUrl = function fullUrl(pathname) {    
  if (env.get('host') == "localhost") {
      host = urlutil.format({
      protocol: env.get('protocol'),
      hostname: env.get('host'),
      port: env.get('port')
    });
  }
  else {
      host = urlutil.format({
      protocol: env.get('protocol'),
      hostname: env.get('host')
    });
  }

  return urlutil.resolve(host, pathname);
};

module.exports = env;
{'fraction_non_alphanumeric': 0.1699429296131896, 'fraction_numerical': 0.0, 'mean_word_length': 4.048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5172497', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1029, 'n_words': 237}