diff --git a/js/app.js b/js/app.js index 4c819706..23078f2a 100644 --- a/js/app.js +++ b/js/app.js @@ -14,8 +14,8 @@ import AppConstants from './constants/application_constants'; import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants'; import { initLogging } from './utils/error'; -import { getSubdomain } from './utils/general'; import requests from './utils/requests'; +import { getCurrentSubdomain } from './utils/url'; // FIXME: rename these event actions @@ -38,7 +38,7 @@ const AppGateway = { let subdomainSettings; try { - subdomainSettings = getSubdomainSettings(getSubdomain()); + subdomainSettings = getSubdomainSettings(getCurrentSubdomain()); } catch (err) { // if there are no matching subdomains, we''ll route to the default frontend console.logGlobal(err); diff --git a/js/components/whitelabel/wallet/wallet_app.js b/js/components/whitelabel/wallet/wallet_app.js index 04a8f44a..82593b2b 100644 --- a/js/components/whitelabel/wallet/wallet_app.js +++ b/js/components/whitelabel/wallet/wallet_app.js @@ -6,7 +6,7 @@ import withContext from '../../context/with_context'; import Header from '../../header'; import { routerShape } from '../../prop_types'; -import { getSubdomain } from '../../../utils/general'; +import { getCurrentSubdomain } from '../../../utils/url'; let WalletApp = React.createClass({ @@ -21,7 +21,7 @@ let WalletApp = React.createClass({ render() { const { activeRoute, children, router, routes } = this.props; - const subdomain = getSubdomain(); + const subdomain = getCurrentSubdomain(); const path = activeRoute && activeRoute.path; const RouteFooterType = activeRoute && activeRoute.footer; diff --git a/js/fetchers/license_fetcher.js b/js/fetchers/license_fetcher.js index 8e1fdce8..67c5c103 100644 --- a/js/fetchers/license_fetcher.js +++ b/js/fetchers/license_fetcher.js @@ -2,7 +2,7 @@ import requests from '../utils/requests'; -import { getSubdomain } from '../utils/general'; +import { getCurrentSubdomain } from '../utils/url'; let LicenseFetcher = { @@ -10,7 +10,7 @@ let LicenseFetcher = { * Fetch the available licenses from the API (might be bound to the subdomain e.g. cc.ascribe.io). */ fetch() { - return requests.get('licenses', {'subdomain': getSubdomain()}); + return requests.get('licenses', { 'subdomain': getCurrentSubdomain() }); } }; diff --git a/js/sources/whitelabel_source.js b/js/sources/whitelabel_source.js index c7749125..ade1b95b 100644 --- a/js/sources/whitelabel_source.js +++ b/js/sources/whitelabel_source.js @@ -3,13 +3,13 @@ import requests from '../utils/requests'; import WhitelabelActions from '../actions/whitelabel_actions'; -import { getSubdomain } from '../utils/general'; +import { getCurrentSubdomain } from '../utils/url'; const WhitelabelSource = { lookupWhitelabel: { remote() { - return requests.get('whitelabel_settings', { 'subdomain': getSubdomain() }); + return requests.get('whitelabel_settings', { 'subdomain': getCurrentSubdomain() }); }, local(state) { diff --git a/js/third_party/intercom_handler.js b/js/third_party/intercom_handler.js index b4486dc6..368ac978 100644 --- a/js/third_party/intercom_handler.js +++ b/js/third_party/intercom_handler.js @@ -3,7 +3,7 @@ import { altThirdParty } from '../alt'; import EventActions from '../actions/event_actions'; -import { getSubdomain } from '../utils/general'; +import { getCurrentSubdomain } from '../utils/url'; class IntercomHandler { @@ -20,7 +20,7 @@ class IntercomHandler { window.Intercom('boot', { app_id: 'oboxh5w1', email: user.email, - subdomain: getSubdomain(), + subdomain: getCurrentSubdomain(), widget: { activator: '#IntercomDefaultWidget' } diff --git a/js/third_party/notifications_handler.js b/js/third_party/notifications_handler.js index ea078953..5f54e34d 100644 --- a/js/third_party/notifications_handler.js +++ b/js/third_party/notifications_handler.js @@ -7,7 +7,7 @@ import EventActions from '../actions/event_actions'; import NotificationActions from '../actions/notification_actions'; -import { getSubdomain } from '../utils/general'; +import { getCurrentSubdomain } from '../utils/url'; class NotificationsHandler { @@ -21,7 +21,7 @@ class NotificationsHandler { return; } - const subdomain = getSubdomain(); + const subdomain = getCurrentSubdomain(); if (subdomain === 'ikonotv') { NotificationActions.fetchContractAgreementListNotifications().then( (res) => { diff --git a/js/utils/general.js b/js/utils/general.js index 42ea3bba..b74b3edf 100644 --- a/js/utils/general.js +++ b/js/utils/general.js @@ -26,14 +26,3 @@ export { export function escapeHTML(s) { return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; } - -/** - * Extracts the user's subdomain from the browser's window. - * If no subdomain is found (for example on a naked domain), the default "www" is just assumed. - * @return {string} subdomain as a string - */ -export function getSubdomain() { - let { host } = window.location; - let tokens = host.split('.'); - return tokens.length > 2 ? tokens[0] : 'www'; -} diff --git a/js/utils/url.js b/js/utils/url.js index 77fba848..f33ed84a 100644 --- a/js/utils/url.js +++ b/js/utils/url.js @@ -2,9 +2,23 @@ export { getCurrentQueryParams, stringifyAsQueryParam, parseQueryParamStr } from 'js-utility-belt/es6/url'; /** - * Takes a string and a boolean and generates a string query parameter for - * an API call. + * Takes a string and a boolean and generates an string ordering query parameter for API calls. + * + * @param {string} orderBy Property to order by + * @param {bool} orderAsc Whether the order should be ascending (false makes order descending) + * @return {string} Ordering query parameter */ export function generateOrderingQueryParams(orderBy, orderAsc) { return orderAsc ? orderBy : `-${orderBy}`; } + +/** + * Extracts the current location's subdomain. + * If no subdomain is found (for example on a naked domain), the default "www" is just assumed. + * + * @return {string} Subdomain (if none found, defaults to "www") + */ +export function getCurrentSubdomain() { + const tokens = window.location.host.split('.'); + return tokens.length > 2 ? tokens[0] : 'www'; +}