Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template all base urls in Globals.js #511

Merged
merged 10 commits into from Apr 14, 2020
@@ -36,7 +36,7 @@ const HomeView = (props) => {
email,
isPlus,
} = props;
const accountHref = `https://account.${globals.GHOSTERY_DOMAIN}.com`;
const accountHref = globals.ACCOUNT_BASE_URL;

let headerInfoText = t('hub_home_header_info');
if (globals.BROWSER_INFO) {
@@ -29,7 +29,7 @@ class PlusView extends Component {
*/
_renderButton = (additionalClasses) => {
const { isPlus, onPlusClick } = this.props;
const buttonHref = `https://checkout.${globals.GHOSTERY_DOMAIN}.com/plus?utm_source=gbe&utm_campaign=intro_hub_plus`;
const buttonHref = `${globals.CHECKOUT_BASE_URL}/plus?utm_source=gbe&utm_campaign=intro_hub_plus`;
const buttonClassNames = ClassNames('PlusView__button', 'button', additionalClasses, {
disabled: isPlus,
});
@@ -57,7 +57,7 @@ class SideNavigationViewContainer extends Component {
{ href: '/products', icon: 'products', text: t('hub_side_navigation_products') }
];
const bottomItems = user ? [
{ id: 'email', href: `https://account.${globals.GHOSTERY_DOMAIN}.com/`, text: user.email },
{ id: 'email', href: `${globals.ACCOUNT_BASE_URL}/`, text: user.email },
{ id: 'logout', text: t('sign_out'), clickHandler: this._handleLogoutClick },
] : [
{ id: 'create-account', href: '/create-account', text: t('create_account') },
@@ -56,7 +56,7 @@ class GlobalTracker extends React.Component {
this.setState({ description: t('tracker_description_getting') });

sendMessageInPromise('getTrackerDescription', {
url: `https://${globals.APPS_SUB_DOMAIN}.ghostery.com/${this.props.language}/apps/${
url: `${globals.APPS_BASE_URL}/${this.props.language}/apps/${
encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}?format=json`,
}).then((data) => {
if (data) {
@@ -114,7 +114,7 @@ class GlobalTracker extends React.Component {
{
this.state.showTrackerLearnMore && (
<div className={(!this.state.showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`https://${globals.APPS_SUB_DOMAIN}.ghostery.com/${this.props.language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.APPS_BASE_URL}/${this.props.language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
{ t('tracker_description_learn_more') }
</a>
</div>
@@ -89,7 +89,7 @@ class Tracker extends React.Component {
this.setState({ description: t('tracker_description_getting') });

sendMessageInPromise('getTrackerDescription', {
url: `https://${globals.APPS_SUB_DOMAIN}.ghostery.com/${this.props.language}/apps/${
url: `${globals.APPS_BASE_URL}/${this.props.language}/apps/${
encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}?format=json`,
}).then((data) => {
if (data) {
@@ -304,7 +304,7 @@ class Tracker extends React.Component {
className="trk-src-link"
title={source.src}
key={index}
href={`https://${encodeURIComponent(globals.GCACHE_SUB_DOMAIN)}.ghostery.com/${encodeURIComponent(this.props.language)}/gcache/?n=${encodeURIComponent(tracker.name)}&s=${encodeURIComponent(source.src)}&v=2&t=${source.type}`}
href={`${globals.GCACHE_BASE_URL}/${encodeURIComponent(this.props.language)}/gcache/?n=${encodeURIComponent(tracker.name)}&s=${encodeURIComponent(source.src)}&v=2&t=${source.type}`}
>
{ source.src }
</a>
@@ -357,7 +357,7 @@ class Tracker extends React.Component {
<div className="trk-description">
{this.state.description}
<div className={(!this.state.showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`https://${globals.APPS_SUB_DOMAIN}.ghostery.com/${this.props.language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.APPS_BASE_URL}/${this.props.language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
{t('tracker_description_learn_more')}
</a>
</div>
@@ -126,7 +126,7 @@ class HeaderMenu extends React.Component {
*/
clickSignedInAs = () => {
sendMessage('openNewTab', {
url: `https://account.${globals.GHOSTERY_DOMAIN}.com/`,
url: `${globals.ACCOUNT_BASE_URL}/`,
become_active: true,
});
window.close();
@@ -37,7 +37,7 @@ class Account extends React.Component {
*/
clickEditAccount = () => {
sendMessage('openNewTab', {
url: `https://account.${globals.GHOSTERY_DOMAIN}.com/`,
url: `${globals.GHOSTERY_ACCOUNT_BASE_URL}/`,
become_active: true,
});
window.close();
@@ -64,11 +64,11 @@ const { sendMessage } = utils;
const { onMessage } = chrome.runtime;
// simple consts
const {
CDN_SUB_DOMAIN, BROWSER_INFO, IS_CLIQZ, DEBUG
CDN_BASE_URL, BROWSER_INFO, IS_CLIQZ, DEBUG
} = globals;
const IS_EDGE = (BROWSER_INFO.name === 'edge');
const IS_FIREFOX = (BROWSER_INFO.name === 'firefox');
const VERSION_CHECK_URL = `https://${CDN_SUB_DOMAIN}.ghostery.com/update/version`;
const VERSION_CHECK_URL = `${CDN_BASE_URL}/update/version`;
const REAL_ESTATE_ID = 'ghostery';
const onBeforeRequest = events.onBeforeRequest.bind(events);
const onHeadersReceived = events.onHeadersReceived.bind(events);
@@ -845,11 +845,11 @@ function onMessageHandler(request, sender, callback) {
return true;
}
if (name === 'account.openSubscriptionPage') {
utils.openNewTab({ url: `https://account.${globals.GHOSTERY_DOMAIN}.com/subscription`, become_active: true });
utils.openNewTab({ url: `${globals.CHECKOUT_BASE_URL}/subscription`, become_active: true });
return false;
}
if (name === 'account.openCheckoutPage') {
let url = `https://checkout.${globals.GHOSTERY_DOMAIN}.com/plus`;
let url = `${globals.CHECKOUT_BASE_URL}/plus`;
const { utm } = message || null;
if (utm) {
url += `?utm_source=${utm.utm_source}&utm_campaign=${utm.utm_campaign}`;
@@ -860,7 +860,7 @@ function onMessageHandler(request, sender, callback) {
if (name === 'account.openSupportPage') {
metrics.ping('priority_support_submit');
const subscriber = account.hasScopesUnverified(['subscriptions:plus']);
const tabUrl = subscriber ? `https://account.${globals.GHOSTERY_DOMAIN}.com/support` : 'https://www.ghostery.com/support/';
const tabUrl = subscriber ? `${globals.ACCOUNT_BASE_URL}/support` : 'https://www.ghostery.com/support/';
utils.openNewTab({ url: tabUrl, become_active: true });
return false;
}
@@ -19,7 +19,7 @@ import globals from './Globals';
import { getJson } from '../utils/utils';
import { log } from '../utils/common';

const { BROWSER_INFO, CMP_SUB_DOMAIN, EXTENSION_VERSION } = globals;
const { BROWSER_INFO, CMP_BASE_URL, EXTENSION_VERSION } = globals;

/** Helper class for handling A/B tests.
* @memberof BackgroundClasses
@@ -44,7 +44,7 @@ class ABTest {
fetch() {
log('A/B Tests: fetching...');

const URL = `https://${CMP_SUB_DOMAIN}.ghostery.com/abtestcheck
const URL = `${CMP_BASE_URL}/abtestcheck
?os=${encodeURIComponent(BROWSER_INFO.os)}
&install_date=${encodeURIComponent(conf.install_date)}
&ir=${encodeURIComponent(conf.install_random_number)}
@@ -25,7 +25,7 @@ import Api from '../utils/api';

const api = new Api();
const {
GHOSTERY_DOMAIN, AUTH_SERVER, ACCOUNT_SERVER, SYNC_ARRAY, IS_CLIQZ
COOKIE_DOMAIN, COOKIE_URL, AUTH_SERVER, ACCOUNT_SERVER, SYNC_ARRAY, IS_CLIQZ
} = globals;

const SYNC_SET = new Set(SYNC_ARRAY);
@@ -35,7 +35,7 @@ class Account {
const apiConfig = {
AUTH_SERVER,
ACCOUNT_SERVER,
CSRF_DOMAIN: GHOSTERY_DOMAIN
COOKIE_URL
};
const opts = {
errorHandler: errors => (
@@ -114,7 +114,7 @@ class Account {
logout = () => (
new RSVP.Promise((resolve, reject) => {
chrome.cookies.get({
url: `https://${GHOSTERY_DOMAIN}.com`,
url: COOKIE_URL,
name: 'csrf_token',
}, (cookie) => {
if (cookie === null) { return reject(); }
@@ -312,7 +312,7 @@ class Account {
return;
}
chrome.cookies.get({
url: `https://${GHOSTERY_DOMAIN}.com`,
url: COOKIE_URL,
name: 'user_id',
}, (cookie) => {
if (cookie !== null) {
@@ -402,8 +402,8 @@ class Account {
chrome.cookies.set({
name,
value,
url: `https://${GHOSTERY_DOMAIN}.com`,
domain: `.${GHOSTERY_DOMAIN}.com`,
url: COOKIE_URL,
domain: COOKIE_DOMAIN,
expirationDate,
secure: true,
httpOnly,
@@ -502,7 +502,7 @@ class Account {
_getUserIDFromCookie = () => (
new Promise((resolve, reject) => {
chrome.cookies.get({
url: `https://${GHOSTERY_DOMAIN}.com`,
url: COOKIE_URL,
name: 'user_id',
}, (cookie) => {
if (cookie) {
@@ -541,7 +541,7 @@ class Account {
const cookies = ['user_id', 'access_token', 'refresh_token', 'csrf_token', 'AUTH'];
cookies.forEach((name) => {
chrome.cookies.remove({
url: `https://${GHOSTERY_DOMAIN}.com`,
url: COOKIE_URL,
name,
}, () => {
log(`Removed cookie with name: ${name}`);
@@ -16,7 +16,7 @@ import globals from './Globals';
import { getJson } from '../utils/utils';
import { log } from '../utils/common';

const { BROWSER_INFO, CMP_SUB_DOMAIN, EXTENSION_VERSION } = globals;
const { BROWSER_INFO, CMP_BASE_URL, EXTENSION_VERSION } = globals;

/**
* Class for handling notification and/or marketing campaigns.
@@ -36,7 +36,7 @@ class CMP {
return Promise.resolve(false);
}

const URL = `https://${CMP_SUB_DOMAIN}.ghostery.com/check
const URL = `${CMP_BASE_URL}/check
?os=${encodeURIComponent(BROWSER_INFO.os)}
&offers=${encodeURIComponent(conf.enable_offers ? '1' : '0')}
&hw=${encodeURIComponent(conf.enable_human_web ? '1' : '0')}
@@ -50,14 +50,19 @@ class Globals {
this.initProps = {};

// domains
this.GHOSTERY_DOMAIN = this.DEBUG ? 'ghosterystage' : 'ghostery';
this.METRICS_SUB_DOMAIN = this.DEBUG ? 'staging-d' : 'd';
this.CMP_SUB_DOMAIN = this.DEBUG ? 'staging-cmp-cdn' : 'cmp-cdn';
this.CDN_SUB_DOMAIN = this.DEBUG ? 'staging-cdn' : 'cdn';
this.APPS_SUB_DOMAIN = this.DEBUG ? 'staging-apps' : 'apps';
this.GCACHE_SUB_DOMAIN = this.DEBUG ? 'staging-gcache' : 'gcache';
This conversation was marked as resolved by fcjr
Comment on lines -53 to -58

This comment has been minimized.

@jsignanini

jsignanini Mar 18, 2020
Member

@fcjr all these keep the ghostery.com domain even on staging, the stage vs prod difference is on the subdomain only.

this.AUTH_SERVER = `https://consumerapi.${this.GHOSTERY_DOMAIN}.com`;
this.ACCOUNT_SERVER = `https://accountapi.${this.GHOSTERY_DOMAIN}.com`;
this.GHOSTERY_ROOT_DOMAIN = `${this.DEBUG ? 'ghosterystage' : 'ghostery'}.com`;
this.GHOSTERY_BASE_URL = `https://${this.GHOSTERY_ROOT_DOMAIN}`;
this.ACCOUNT_BASE_URL = `https://account.${this.GHOSTERY_ROOT_DOMAIN}`;
this.CHECKOUT_BASE_URL = `https://checkout.${this.GHOSTERY_ROOT_DOMAIN}`;
this.METRICS_BASE_URL = `https://${this.DEBUG ? 'staging-d' : 'd'}.ghostery.com`;
this.CMP_BASE_URL = `https://${this.DEBUG ? 'staging-cmp-cdn' : 'cmp-cdn'}.ghostery.com`;
this.CDN_BASE_URL = `https://${this.DEBUG ? 'staging-cdn' : 'cdn'}.ghostery.com`;
this.APPS_BASE_URL = `https://${this.DEBUG ? 'staging-apps' : 'apps'}.ghostery.com`;
this.GCACHE_BASE_URL = `https://${this.DEBUG ? 'staging-gcache' : 'gcache'}.ghostery.com`;
this.AUTH_SERVER = `https://consumerapi.${this.GHOSTERY_ROOT_DOMAIN}`;
this.ACCOUNT_SERVER = `https://accountapi.${this.GHOSTERY_ROOT_DOMAIN}`;
this.COOKIE_DOMAIN = `.${this.GHOSTERY_ROOT_DOMAIN}`;
this.COOKIE_URL = this.GHOSTERY_BASE_URL;

// extension IDs
this.GHOSTERY_TAB_CHROME_PRODUCTION_ID = 'plmapebanmikcofllaaddgeocahboejc';
@@ -25,7 +25,7 @@ const FREQUENCIES = { // in milliseconds
};
const CRITICAL_METRICS = ['install', 'install_complete', 'upgrade', 'active', 'engaged', 'uninstall'];
const CAMPAIGN_METRICS = ['install', 'active', 'uninstall'];
const { METRICS_SUB_DOMAIN, EXTENSION_VERSION, BROWSER_INFO } = globals;
const { METRICS_BASE_URL, EXTENSION_VERSION, BROWSER_INFO } = globals;
const MAX_DELAYED_PINGS = 100;

// Note that this threshold is intentionally different from the 30 second threshold in PolicySmartBlock,
@@ -299,7 +299,7 @@ class Metrics {
_buildMetricsUrl(type, frequency) {
const frequencyString = (type !== 'uninstall') ? `/${frequency}` : '';

let metrics_url = `https://${METRICS_SUB_DOMAIN}.ghostery.com/${type}${frequencyString}?gr=-1` +
let metrics_url = `${METRICS_BASE_URL}/${type}${frequencyString}?gr=-1` +
// Old parameters, old names
// Human web
`&hw=${encodeURIComponent(conf.enable_human_web ? '1' : '0')}` +
@@ -17,7 +17,7 @@ import conf from './Conf';
import { getJson, fetchLocalJSONResource } from '../utils/utils';
import { log } from '../utils/common';

const { CDN_SUB_DOMAIN } = globals;
const { CDN_BASE_URL } = globals;
/**
* Base class for BugDb, Click2PlayDb, CompatibilityDb and SurrogateDb.
* It provides update functionality, which all of these subclasses
@@ -131,7 +131,7 @@ class Updatable {
*/
_remoteFetcher(callback) {
log(`fetching ${this.type} from remote`);
const UPDATE_URL = `https://${CDN_SUB_DOMAIN}.ghostery.com/update/${
const UPDATE_URL = `${CDN_BASE_URL}/update/${
this.type === 'bugs' ? 'v3/bugs' : this.type}`;

getJson(UPDATE_URL).then((list) => {
@@ -139,10 +139,10 @@ class Api {
});
}

_getCsrfCookie = (csrfDomain = this.config.CSRF_DOMAIN) => (
_getCsrfCookie = (cookieUrl = this.config.COOKIE_URL) => (
new Promise((resolve) => {
chrome.cookies.get({
url: `https://${csrfDomain}.com`,
url: cookieUrl,
name: 'csrf_token',
}, cookie => resolve((cookie !== null) ? cookie.value : ''));
})
@@ -130,7 +130,7 @@ export function buildRedirectC2P(requestId, redirectUrls, app_id) {
'blocked_redirect_prevent',
// It is unlikely that apps pages will ever be translated
// [host_url, redirect_url, app_name, 'https://' + globals.APPS_SUB_DOMAIN + '.ghostery.com/' + conf.language + '/apps/' + encodeURIComponent(app_name.replace(/\s+/g, '_').toLowerCase())]),
[host_url, redirect_url, app_name, `https://${globals.APPS_SUB_DOMAIN}.ghostery.com/en/apps/${encodeURIComponent(app_name.replace(/\s+/g, '_').toLowerCase())}`]
[host_url, redirect_url, app_name, `${globals.APPS_BASE_URL}/en/apps/${encodeURIComponent(app_name.replace(/\s+/g, '_').toLowerCase())}`]
),
blocked_redirect_action_always_title: t('blocked_redirect_action_always_title'),
blocked_redirect_action_through_once_title: t('blocked_redirect_action_through_once_title'),
ProTip! Use n and p to navigate between commits in a pull request.