1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-25 18:56:28 +02:00

Move getSubdomain to url utils

This commit is contained in:
Brett Sun 2016-06-13 17:33:47 +02:00
parent ad2b7c223c
commit 4d4cb7f505
8 changed files with 28 additions and 25 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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() });
}
};

View File

@ -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) {

View File

@ -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'
}

View File

@ -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) => {

View File

@ -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';
}

View File

@ -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';
}