From c335dd38826485dbe4a6906aadf7c5f670524316 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 4 Jan 2016 13:08:32 +0100 Subject: [PATCH 1/3] On subdomain get error, use the default subdomain settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also small cleanups and avoids adding `client—undefined` class to body for default subdomain --- js/app.js | 32 ++++++++++++++------------------ js/routes.js | 12 ++++-------- js/utils/constants_utils.js | 14 +++++++++----- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/js/app.js b/js/app.js index dc8204cf..42ad1473 100644 --- a/js/app.js +++ b/js/app.js @@ -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 = (); - 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); diff --git a/js/routes.js b/js/routes.js index 49a284af..025a0fb6 100644 --- a/js/routes.js +++ b/js/routes.js @@ -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 = ( 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.'); } From 4a3a368fc50b303db266d13f22ee92994cfd9b21 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 4 Jan 2016 13:09:03 +0100 Subject: [PATCH 2/3] Remove unused `logo` and `permissions` fields from subdomain constants --- js/constants/application_constants.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/js/constants/application_constants.js b/js/constants/application_constants.js index 824ed4b2..a230eb0c 100644 --- a/js/constants/application_constants.js +++ b/js/constants/application_constants.js @@ -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' } ], From 3c72ee331d847416d3f30dc924b48682ac99958c Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 4 Jan 2016 13:14:50 +0100 Subject: [PATCH 3/3] Convert AppGateway to be single instance --- js/app.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/js/app.js b/js/app.js index 42ad1473..9118fbe3 100644 --- a/js/app.js +++ b/js/app.js @@ -33,22 +33,8 @@ import NotificationsHandler from './third_party/notifications'; import FacebookHandler from './third_party/facebook'; /* eslint-enable */ -initLogging(); -let headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json' -}; - -requests.defaults({ - urlMap: ApiUrls, - http: { - headers: headers, - credentials: 'include' - } -}); - -class AppGateway { +const AppGateway = { start() { try { const subdomain = getSubdomain(); @@ -63,7 +49,7 @@ class AppGateway { console.logGlobal(err); this.load(getDefaultSubdomainSettings()); } - } + }, load(settings) { const { subdomain, type } = settings; @@ -97,8 +83,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();