mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Move getSubdomain to url utils
This commit is contained in:
parent
ad2b7c223c
commit
4d4cb7f505
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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) {
|
||||
|
4
js/third_party/intercom_handler.js
vendored
4
js/third_party/intercom_handler.js
vendored
@ -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'
|
||||
}
|
||||
|
4
js/third_party/notifications_handler.js
vendored
4
js/third_party/notifications_handler.js
vendored
@ -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) => {
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -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';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user