1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Write generic function for extracting subdomain and implement troughout whole app

This commit is contained in:
Tim Daubenschütz 2015-09-29 14:58:56 +02:00
parent 8e62206a21
commit d50d0faabe
8 changed files with 39 additions and 11 deletions

View File

@ -10,13 +10,15 @@ import fetch from 'isomorphic-fetch';
/* eslint-enable */
import ApiUrls from './constants/api_urls';
import { updateApiUrls } from './constants/api_urls';
import appConstants from './constants/application_constants';
import AppConstants from './constants/application_constants';
import getRoutes from './routes';
import requests from './utils/requests';
import { updateApiUrls } from './constants/api_urls';
import { getSubdomainSettings } from './utils/constants_utils';
import { initLogging } from './utils/error_utils';
import { getSubdomain } from './utils/general_utils';
import EventActions from './actions/event_actions';
@ -48,11 +50,11 @@ requests.defaults({
class AppGateway {
start() {
let settings;
let subdomain = window.location.host.split('.')[0];
let subdomain = getSubdomain();
try {
settings = getSubdomainSettings(subdomain);
appConstants.whitelabel = settings;
AppConstants.whitelabel = settings;
updateApiUrls(settings.type, subdomain);
this.load(settings);
} catch(err) {

View File

@ -9,6 +9,9 @@ import GlobalNotification from '../../global_notification';
import getRoutes from './prize_routes';
import { getSubdomain } from '../../../utils/general_utils';
let RouteHandler = Router.RouteHandler;
let PrizeApp = React.createClass({
@ -16,7 +19,7 @@ let PrizeApp = React.createClass({
render() {
let header = null;
let subdomain = window.location.host.split('.')[0];
let subdomain = getSubdomain();
let ROUTES = getRoutes(null, subdomain);

View File

@ -10,6 +10,8 @@ import GlobalNotification from '../../global_notification';
import getRoutes from './wallet_routes';
import classNames from 'classnames';
import { getSubdomain } from '../../../utils/general_utils';
let RouteHandler = Router.RouteHandler;
@ -18,7 +20,7 @@ let WalletApp = React.createClass({
mixins: [Router.State],
render() {
let subdomain = window.location.host.split('.')[0];
let subdomain = getSubdomain();
let ROUTES = getRoutes(null, subdomain);
let activeRoutes = this.getRoutes().map(elem => 'route--' + elem.name);

View File

@ -2,12 +2,15 @@
import requests from '../utils/requests';
import { getSubdomain } from '../utils/general_utils';
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': window.location.host.split('.')[0]});
return requests.get('licenses', {'subdomain': getSubdomain()});
}
};

View File

@ -2,12 +2,15 @@
import requests from '../utils/requests';
import { getSubdomain } from '../utils/general_utils';
let WhitelabelFetcher = {
/**
* Fetch the custom whitelabel data from the API.
*/
fetch() {
return requests.get('whitelabel_settings', {'subdomain': window.location.host.split('.')[0]});
return requests.get('whitelabel_settings', {'subdomain': getSubdomain()});
}
};

View File

@ -3,6 +3,8 @@
import alt from '../alt';
import EventActions from '../actions/event_actions';
import { getSubdomain } from '../utils/general_utils';
class IntercomHandler {
constructor() {
@ -20,7 +22,7 @@ class IntercomHandler {
/* eslint-enable */
app_id: 'oboxh5w1',
email: profile.email,
subdomain: window.location.host.split('.')[0],
subdomain: getSubdomain(),
widget: {
activator: '#IntercomDefaultWidget'
}

View File

@ -5,6 +5,8 @@ import EventActions from '../actions/event_actions';
import NotificationActions from '../actions/notification_actions';
import { getSubdomain } from '../utils/general_utils';
class NotificationsHandler {
@ -13,11 +15,11 @@ class NotificationsHandler {
this.loaded = false;
}
onProfileDidLoad(profile) {
onProfileDidLoad() {
if (this.loaded) {
return;
}
let subdomain = window.location.host.split('.')[0];
let subdomain = getSubdomain();
if (subdomain === 'ikonotv') {
NotificationActions.fetchContractAgreementListNotifications().then(
(res) => {

View File

@ -221,4 +221,15 @@ export function truncateTextAtCharIndex(text, charIndex, replacement = '...') {
truncatedText += text.length > charIndex ? replacement : '';
return truncatedText;
}
/**
* 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 matchedHost = host.match(/(([^.]+)\.)?(.*)\.(.*)/);
return matchedHost[2] || 'www';
}