1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Merge pull request #90 from ascribe/refactor-subdomain-settings

Refactor subdomain settings constants
This commit is contained in:
Brett Sun 2016-01-19 16:43:06 +01:00
commit 2f4534f14e
4 changed files with 46 additions and 64 deletions

View File

@ -16,7 +16,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';
@ -30,28 +30,13 @@ import IntercomHandler from './third_party/intercom_handler';
import NotificationsHandler from './third_party/notifications_handler';
import RavenHandler from './third_party/raven_handler';
initLogging();
let headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
};
requests.defaults({
urlMap: ApiUrls,
http: {
headers: headers,
credentials: 'include'
}
});
class AppGateway {
const 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);
@ -59,28 +44,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);
@ -98,7 +80,21 @@ class AppGateway {
// Send the applicationDidBoot event to the third-party stores
EventActions.applicationDidBoot(settings);
}
}
};
let ag = new AppGateway();
ag.start();
// Initialize pre-start components
initLogging();
requests.defaults({
urlMap: ApiUrls,
http: {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
credentials: 'include'
}
});
// And bootstrap app
AppGateway.start();

View File

@ -24,52 +24,38 @@ const constants = {
{
'subdomain': 'cc',
'name': 'Creative Commons France',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/public/creativecommons/cc.logo.sm.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet',
'ga': 'UA-60614729-4'
},
{
'subdomain': 'sluice',
'name': 'Sluice Art Fair',
'logo': 'http://sluice.info/images/logo.gif',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'prize',
'ga': 'UA-60614729-5'
},
{
'subdomain': 'cyland',
'name': 'Cyland media art lab',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/cyland/logo.gif',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet'
},
{
'subdomain': 'ikonotv',
'name': 'IkonoTV',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/ikonotv/ikono-logo-black.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet'
},
{
'subdomain': 'lumenus',
'name': 'Lumenus',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/lumenus/lumenus-logo.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet'
},
{
'subdomain': '23vivi',
'name': '23VIVI',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/23vivi/23vivi-logo.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet'
},
{
'subdomain': 'portfolioreview',
'name': 'Portfolio Review',
'logo': 'http://notfoundlogo.de',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'prize'
}
],

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.');
}