mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +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:
parent
f819e1313e
commit
c335dd3882
26
js/app.js
26
js/app.js
@ -17,7 +17,7 @@ import getRoutes from './routes';
|
|||||||
import requests from './utils/requests';
|
import requests from './utils/requests';
|
||||||
|
|
||||||
import { updateApiUrls } from './constants/api_urls';
|
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 { initLogging } from './utils/error_utils';
|
||||||
import { getSubdomain } from './utils/general_utils';
|
import { getSubdomain } from './utils/general_utils';
|
||||||
|
|
||||||
@ -50,11 +50,10 @@ requests.defaults({
|
|||||||
|
|
||||||
class AppGateway {
|
class AppGateway {
|
||||||
start() {
|
start() {
|
||||||
let settings;
|
|
||||||
let subdomain = getSubdomain();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
settings = getSubdomainSettings(subdomain);
|
const subdomain = getSubdomain();
|
||||||
|
const settings = getSubdomainSettings(subdomain);
|
||||||
|
|
||||||
AppConstants.whitelabel = settings;
|
AppConstants.whitelabel = settings;
|
||||||
updateApiUrls(settings.type, subdomain);
|
updateApiUrls(settings.type, subdomain);
|
||||||
this.load(settings);
|
this.load(settings);
|
||||||
@ -62,27 +61,24 @@ class AppGateway {
|
|||||||
// if there are no matching subdomains, we're routing
|
// if there are no matching subdomains, we're routing
|
||||||
// to the default frontend
|
// to the default frontend
|
||||||
console.logGlobal(err);
|
console.logGlobal(err);
|
||||||
this.load();
|
this.load(getDefaultSubdomainSettings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load(settings) {
|
load(settings) {
|
||||||
let type = 'default';
|
const { subdomain, type } = settings;
|
||||||
let subdomain = 'www';
|
|
||||||
let redirectRoute = (<Redirect from="/" to="/collection" />);
|
let redirectRoute = (<Redirect from="/" to="/collection" />);
|
||||||
|
|
||||||
if (settings) {
|
if (subdomain) {
|
||||||
type = settings.type;
|
// Some whitelabels have landing pages so we should not automatically redirect from / to /collection.
|
||||||
subdomain = settings.subdomain;
|
// Only www and cc do not have a landing page.
|
||||||
}
|
if (subdomain !== 'cc') {
|
||||||
|
|
||||||
// www and cc do not have a landing page
|
|
||||||
if(subdomain && subdomain !== 'cc') {
|
|
||||||
redirectRoute = null;
|
redirectRoute = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a client specific class to the body for whitelabel styling
|
// Adds a client specific class to the body for whitelabel styling
|
||||||
window.document.body.classList.add('client--' + subdomain);
|
window.document.body.classList.add('client--' + subdomain);
|
||||||
|
}
|
||||||
|
|
||||||
// Send the applicationWillBoot event to the third-party stores
|
// Send the applicationWillBoot event to the third-party stores
|
||||||
EventActions.applicationWillBoot(settings);
|
EventActions.applicationWillBoot(settings);
|
||||||
|
12
js/routes.js
12
js/routes.js
@ -28,7 +28,7 @@ import RegisterPiece from './components/register_piece';
|
|||||||
import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_handler';
|
import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_handler';
|
||||||
|
|
||||||
|
|
||||||
let COMMON_ROUTES = (
|
const COMMON_ROUTES = (
|
||||||
<Route path='/' component={App}>
|
<Route path='/' component={App}>
|
||||||
<Route
|
<Route
|
||||||
path='login'
|
path='login'
|
||||||
@ -65,17 +65,13 @@ let COMMON_ROUTES = (
|
|||||||
|
|
||||||
|
|
||||||
function getRoutes(type, subdomain) {
|
function getRoutes(type, subdomain) {
|
||||||
let routes = null;
|
|
||||||
|
|
||||||
if (type === 'prize') {
|
if (type === 'prize') {
|
||||||
routes = getPrizeRoutes(COMMON_ROUTES, subdomain);
|
return getPrizeRoutes(COMMON_ROUTES, subdomain);
|
||||||
} else if(type === 'wallet') {
|
} else if(type === 'wallet') {
|
||||||
routes = getWalletRoutes(COMMON_ROUTES, subdomain);
|
return getWalletRoutes(COMMON_ROUTES, subdomain);
|
||||||
} else {
|
} else {
|
||||||
routes = COMMON_ROUTES;
|
return COMMON_ROUTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return routes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import appConstants from '../constants/application_constants';
|
import AppConstants from '../constants/application_constants';
|
||||||
|
|
||||||
|
export function getDefaultSubdomainSettings() {
|
||||||
|
return AppConstants.defaultDomain;
|
||||||
|
}
|
||||||
|
|
||||||
export function getSubdomainSettings(subdomain) {
|
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];
|
return settings[0];
|
||||||
} else if (settings.length === 0) {
|
} else if (settings.length === 0) {
|
||||||
console.warn('There are no subdomain settings for the subdomain: ' + subdomain);
|
console.warn('There are no subdomain settings for the subdomain: ' + subdomain);
|
||||||
return appConstants.defaultDomain;
|
return AppConstants.defaultDomain;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Matched multiple subdomains. Adjust constants file.');
|
throw new Error('Matched multiple subdomains. Adjust constants file.');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user