mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Merge pull request #90 from ascribe/refactor-subdomain-settings
Refactor subdomain settings constants
This commit is contained in:
commit
2f4534f14e
64
js/app.js
64
js/app.js
@ -16,7 +16,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';
|
||||||
|
|
||||||
@ -30,28 +30,13 @@ import IntercomHandler from './third_party/intercom_handler';
|
|||||||
import NotificationsHandler from './third_party/notifications_handler';
|
import NotificationsHandler from './third_party/notifications_handler';
|
||||||
import RavenHandler from './third_party/raven_handler';
|
import RavenHandler from './third_party/raven_handler';
|
||||||
|
|
||||||
initLogging();
|
|
||||||
|
|
||||||
let headers = {
|
const AppGateway = {
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
};
|
|
||||||
|
|
||||||
requests.defaults({
|
|
||||||
urlMap: ApiUrls,
|
|
||||||
http: {
|
|
||||||
headers: headers,
|
|
||||||
credentials: 'include'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
||||||
@ -59,27 +44,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);
|
||||||
@ -98,7 +80,21 @@ class AppGateway {
|
|||||||
// Send the applicationDidBoot event to the third-party stores
|
// Send the applicationDidBoot event to the third-party stores
|
||||||
EventActions.applicationDidBoot(settings);
|
EventActions.applicationDidBoot(settings);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let ag = new AppGateway();
|
// Initialize pre-start components
|
||||||
ag.start();
|
initLogging();
|
||||||
|
|
||||||
|
requests.defaults({
|
||||||
|
urlMap: ApiUrls,
|
||||||
|
http: {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
credentials: 'include'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// And bootstrap app
|
||||||
|
AppGateway.start();
|
||||||
|
@ -24,52 +24,38 @@ const constants = {
|
|||||||
{
|
{
|
||||||
'subdomain': 'cc',
|
'subdomain': 'cc',
|
||||||
'name': 'Creative Commons France',
|
'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',
|
'type': 'wallet',
|
||||||
'ga': 'UA-60614729-4'
|
'ga': 'UA-60614729-4'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': 'sluice',
|
'subdomain': 'sluice',
|
||||||
'name': 'Sluice Art Fair',
|
'name': 'Sluice Art Fair',
|
||||||
'logo': 'http://sluice.info/images/logo.gif',
|
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
|
|
||||||
'type': 'prize',
|
'type': 'prize',
|
||||||
'ga': 'UA-60614729-5'
|
'ga': 'UA-60614729-5'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': 'cyland',
|
'subdomain': 'cyland',
|
||||||
'name': 'Cyland media art lab',
|
'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'
|
'type': 'wallet'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': 'ikonotv',
|
'subdomain': 'ikonotv',
|
||||||
'name': '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'
|
'type': 'wallet'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': 'lumenus',
|
'subdomain': 'lumenus',
|
||||||
'name': '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'
|
'type': 'wallet'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': '23vivi',
|
'subdomain': '23vivi',
|
||||||
'name': '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'
|
'type': 'wallet'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'subdomain': 'portfolioreview',
|
'subdomain': 'portfolioreview',
|
||||||
'name': 'Portfolio Review',
|
'name': 'Portfolio Review',
|
||||||
'logo': 'http://notfoundlogo.de',
|
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
|
|
||||||
'type': 'prize'
|
'type': 'prize'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
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