mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 09:35:10 +01:00
use local whitelabel constants for route switching
This commit is contained in:
parent
8d15238818
commit
5ef63fbba3
25
js/app.js
25
js/app.js
@ -8,10 +8,12 @@ import Router from 'react-router';
|
|||||||
import fetch from 'isomorphic-fetch';
|
import fetch from 'isomorphic-fetch';
|
||||||
|
|
||||||
import ApiUrls from './constants/api_urls';
|
import ApiUrls from './constants/api_urls';
|
||||||
import constants from './constants/application_constants';
|
import appConstants from './constants/application_constants';
|
||||||
import getRoutes from './routes';
|
import getRoutes from './routes';
|
||||||
import requests from './utils/requests';
|
import requests from './utils/requests';
|
||||||
|
|
||||||
|
import { getSubdomainSettings } from './utils/constants_utils';
|
||||||
|
|
||||||
let headers = {
|
let headers = {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -33,26 +35,21 @@ requests.defaults({
|
|||||||
class AppGateway {
|
class AppGateway {
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
console.log('start');
|
let settings;
|
||||||
let subdomain = window.location.host.split('.')[0];
|
let subdomain = window.location.host.split('.')[0];
|
||||||
requests.get('whitelabel_settings', {'subdomain': subdomain})
|
|
||||||
.then(this.loadSubdomain.bind(this))
|
|
||||||
.catch(this.loadDefault.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
loadSubdomain(data) {
|
try {
|
||||||
let settings = data.whitelabel;
|
settings = getSubdomainSettings(subdomain);
|
||||||
constants.whitelabel = settings;
|
appConstants.whitelabel = settings;
|
||||||
this.load('prize');
|
this.load('prize');
|
||||||
}
|
} catch(err) {
|
||||||
|
// if there are no matching subdomains, we're routing
|
||||||
loadDefault(error) {
|
// to the default frontend
|
||||||
console.log('Loading default app, error'. error);
|
|
||||||
this.load('default');
|
this.load('default');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
load(type) {
|
load(type) {
|
||||||
console.log('loading', type);
|
|
||||||
Router.run(getRoutes(type), Router.HistoryLocation, (App) => {
|
Router.run(getRoutes(type), Router.HistoryLocation, (App) => {
|
||||||
React.render(
|
React.render(
|
||||||
<App />,
|
<App />,
|
||||||
|
@ -14,48 +14,32 @@ let constants = {
|
|||||||
|
|
||||||
'subdomains': [
|
'subdomains': [
|
||||||
{
|
{
|
||||||
'fields': {
|
|
||||||
'user': 22,
|
'user': 22,
|
||||||
'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',
|
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/public/creativecommons/cc.logo.sm.png',
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
||||||
},
|
},
|
||||||
'model': 'whitelabel.whitelabelsettings',
|
|
||||||
'pk': 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
'fields': {
|
|
||||||
'user': 22,
|
'user': 22,
|
||||||
'subdomain': 'cc-staging',
|
'subdomain': 'cc-staging',
|
||||||
'name': 'Creative Commons France',
|
'name': 'Creative Commons France',
|
||||||
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/public/creativecommons/cc.logo.sm.png',
|
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/public/creativecommons/cc.logo.sm.png',
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
||||||
},
|
|
||||||
'model': 'whitelabel.whitelabelsettings',
|
|
||||||
'pk': 2
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'fields': {
|
|
||||||
'user': 1,
|
'user': 1,
|
||||||
'subdomain': 'sluice',
|
'subdomain': 'sluice',
|
||||||
'name': 'Sluice Art Fair',
|
'name': 'Sluice Art Fair',
|
||||||
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/sluice/logo.jpeg',
|
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/sluice/logo.jpeg',
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
||||||
},
|
},
|
||||||
'model': 'whitelabel.whitelabelsettings',
|
|
||||||
'pk': 3
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
'fields': {
|
|
||||||
'user': 1,
|
'user': 1,
|
||||||
'subdomain': 'sluice-staging',
|
'subdomain': 'sluice-staging',
|
||||||
'name': 'Sluice Art Fair',
|
'name': 'Sluice Art Fair',
|
||||||
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/sluice/logo.jpeg',
|
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/sluice/logo.jpeg',
|
||||||
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
'permissions': ['register', 'edit', 'share', 'del_from_collection']
|
||||||
},
|
|
||||||
'model': 'whitelabel.whitelabelsettings',
|
|
||||||
'pk': 4
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
15
js/utils/constants_utils.js
Normal file
15
js/utils/constants_utils.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import appConstants from '../constants/application_constants';
|
||||||
|
|
||||||
|
export function getSubdomainSettings(subdomain) {
|
||||||
|
let settings = appConstants.subdomains.filter((sdSettings) => subdomain === sdSettings.subdomain);
|
||||||
|
|
||||||
|
if(settings.length === 1) {
|
||||||
|
return settings[0];
|
||||||
|
} else if(settings.length === 0) {
|
||||||
|
throw new Error('There are no subdomain settings for the subdomain: ' + subdomain);
|
||||||
|
} else {
|
||||||
|
throw new Error('Matched multiple subdomains. Adjust constants file.');
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,8 @@ export function getCookie(name) {
|
|||||||
|
|
||||||
Taken from: http://jsfiddle.net/jan_miksovsky/yy7zs/
|
Taken from: http://jsfiddle.net/jan_miksovsky/yy7zs/
|
||||||
|
|
||||||
|
CURRENTLY NOT USED...
|
||||||
|
|
||||||
*/
|
*/
|
||||||
export function fetchImageAsBlob(url) {
|
export function fetchImageAsBlob(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user