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

On subdomain get error, use the default subdomain settings

Also small cleanups and avoids adding `client—undefined` class to body
for default subdomain
This commit is contained in:
Brett Sun 2016-01-04 13:08:32 +01:00
parent f819e1313e
commit c335dd3882
3 changed files with 27 additions and 31 deletions

View File

@ -17,7 +17,7 @@ import getRoutes from './routes';
import requests from './utils/requests';
import { updateApiUrls } from './constants/api_urls';
import { getSubdomainSettings } from './utils/constants_utils';
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils';
import { initLogging } from './utils/error_utils';
import { getSubdomain } from './utils/general_utils';
@ -50,11 +50,10 @@ requests.defaults({
class AppGateway {
start() {
let settings;
let subdomain = getSubdomain();
try {
settings = getSubdomainSettings(subdomain);
const subdomain = getSubdomain();
const settings = getSubdomainSettings(subdomain);
AppConstants.whitelabel = settings;
updateApiUrls(settings.type, subdomain);
this.load(settings);
@ -62,28 +61,25 @@ class AppGateway {
// if there are no matching subdomains, we're routing
// to the default frontend
console.logGlobal(err);
this.load();
this.load(getDefaultSubdomainSettings());
}
}
load(settings) {
let type = 'default';
let subdomain = 'www';
const { subdomain, type } = settings;
let redirectRoute = (<Redirect from="/" to="/collection" />);
if (settings) {
type = settings.type;
subdomain = settings.subdomain;
}
if (subdomain) {
// Some whitelabels have landing pages so we should not automatically redirect from / to /collection.
// Only www and cc do not have a landing page.
if (subdomain !== 'cc') {
redirectRoute = null;
}
// www and cc do not have a landing page
if(subdomain && subdomain !== 'cc') {
redirectRoute = null;
// Adds a client specific class to the body for whitelabel styling
window.document.body.classList.add('client--' + subdomain);
}
// Adds a client specific class to the body for whitelabel styling
window.document.body.classList.add('client--' + subdomain);
// Send the applicationWillBoot event to the third-party stores
EventActions.applicationWillBoot(settings);

View File

@ -28,7 +28,7 @@ import RegisterPiece from './components/register_piece';
import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_handler';
let COMMON_ROUTES = (
const COMMON_ROUTES = (
<Route path='/' component={App}>
<Route
path='login'
@ -65,17 +65,13 @@ let COMMON_ROUTES = (
function getRoutes(type, subdomain) {
let routes = null;
if (type === 'prize') {
routes = getPrizeRoutes(COMMON_ROUTES, subdomain);
return getPrizeRoutes(COMMON_ROUTES, subdomain);
} else if(type === 'wallet') {
routes = getWalletRoutes(COMMON_ROUTES, subdomain);
return getWalletRoutes(COMMON_ROUTES, subdomain);
} else {
routes = COMMON_ROUTES;
return COMMON_ROUTES;
}
return routes;
}

View File

@ -1,15 +1,19 @@
'use strict';
import appConstants from '../constants/application_constants';
import AppConstants from '../constants/application_constants';
export function getDefaultSubdomainSettings() {
return AppConstants.defaultDomain;
}
export function getSubdomainSettings(subdomain) {
let settings = appConstants.subdomains.filter((sdSettings) => subdomain === sdSettings.subdomain);
const settings = AppConstants.subdomains.filter((sdSettings) => subdomain === sdSettings.subdomain);
if(settings.length === 1) {
if (settings.length === 1) {
return settings[0];
} else if(settings.length === 0) {
} else if (settings.length === 0) {
console.warn('There are no subdomain settings for the subdomain: ' + subdomain);
return appConstants.defaultDomain;
return AppConstants.defaultDomain;
} else {
throw new Error('Matched multiple subdomains. Adjust constants file.');
}