2015-05-13 16:26:12 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-17 16:09:47 +01:00
|
|
|
import 'babel/polyfill';
|
2016-01-05 13:38:58 +01:00
|
|
|
import 'classlist-polyfill';
|
2015-07-03 10:40:04 +02:00
|
|
|
|
2015-05-13 16:26:12 +02:00
|
|
|
import React from 'react';
|
2015-10-01 14:30:11 +02:00
|
|
|
import { Router, Redirect } from 'react-router';
|
2015-10-05 11:52:23 +02:00
|
|
|
import history from './history';
|
2015-06-01 14:22:04 +02:00
|
|
|
|
2015-06-16 13:48:48 +02:00
|
|
|
import fetch from 'isomorphic-fetch';
|
2015-05-15 15:38:25 +02:00
|
|
|
|
2015-06-01 14:22:04 +02:00
|
|
|
import ApiUrls from './constants/api_urls';
|
2015-09-29 14:58:56 +02:00
|
|
|
|
|
|
|
import AppConstants from './constants/application_constants';
|
2015-07-10 16:43:35 +02:00
|
|
|
import getRoutes from './routes';
|
2015-06-16 13:48:48 +02:00
|
|
|
import requests from './utils/requests';
|
2015-06-01 14:22:04 +02:00
|
|
|
|
2015-09-29 14:58:56 +02:00
|
|
|
import { updateApiUrls } from './constants/api_urls';
|
2016-01-04 13:08:32 +01:00
|
|
|
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils';
|
2015-07-17 15:41:09 +02:00
|
|
|
import { initLogging } from './utils/error_utils';
|
2015-09-29 14:58:56 +02:00
|
|
|
import { getSubdomain } from './utils/general_utils';
|
2015-07-17 15:41:09 +02:00
|
|
|
|
2015-07-27 18:06:02 +02:00
|
|
|
import EventActions from './actions/event_actions';
|
2015-07-27 18:21:20 +02:00
|
|
|
|
|
|
|
// You can comment out the modules you don't need
|
2016-01-06 15:23:48 +01:00
|
|
|
// import DebugHandler from './third_party/debug_handler';
|
|
|
|
import NotificationsHandler from './third_party/notifications_handler';
|
2015-05-20 11:23:50 +02:00
|
|
|
|
2016-01-04 13:14:50 +01:00
|
|
|
const AppGateway = {
|
2015-07-10 16:43:35 +02:00
|
|
|
start() {
|
2015-07-14 17:12:32 +02:00
|
|
|
try {
|
2016-01-04 13:08:32 +01:00
|
|
|
const subdomain = getSubdomain();
|
|
|
|
const settings = getSubdomainSettings(subdomain);
|
|
|
|
|
2015-09-29 14:58:56 +02:00
|
|
|
AppConstants.whitelabel = settings;
|
2015-07-14 21:15:10 +02:00
|
|
|
updateApiUrls(settings.type, subdomain);
|
2015-07-27 18:06:02 +02:00
|
|
|
this.load(settings);
|
2015-07-14 17:12:32 +02:00
|
|
|
} catch(err) {
|
|
|
|
// if there are no matching subdomains, we're routing
|
|
|
|
// to the default frontend
|
2015-07-17 15:52:53 +02:00
|
|
|
console.logGlobal(err);
|
2016-01-04 13:08:32 +01:00
|
|
|
this.load(getDefaultSubdomainSettings());
|
2015-07-14 17:12:32 +02:00
|
|
|
}
|
2016-01-04 13:14:50 +01:00
|
|
|
},
|
2015-07-10 16:43:35 +02:00
|
|
|
|
2015-07-27 18:06:02 +02:00
|
|
|
load(settings) {
|
2016-01-04 13:08:32 +01:00
|
|
|
const { subdomain, type } = settings;
|
2015-10-01 15:57:46 +02:00
|
|
|
let redirectRoute = (<Redirect from="/" to="/collection" />);
|
2015-08-11 17:40:26 +02:00
|
|
|
|
2016-01-04 13:08:32 +01:00
|
|
|
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.
|
2016-10-14 14:00:20 +02:00
|
|
|
if (subdomain !== 'cc' && subdomain !== 'bokk') {
|
2016-01-04 13:08:32 +01:00
|
|
|
redirectRoute = null;
|
|
|
|
}
|
2015-09-21 16:23:18 +02:00
|
|
|
|
2016-01-04 13:08:32 +01:00
|
|
|
// Adds a client specific class to the body for whitelabel styling
|
|
|
|
window.document.body.classList.add('client--' + subdomain);
|
2015-10-01 15:57:46 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 17:09:46 +02:00
|
|
|
// Send the applicationWillBoot event to the third-party stores
|
2015-07-27 18:06:02 +02:00
|
|
|
EventActions.applicationWillBoot(settings);
|
2015-09-30 17:09:46 +02:00
|
|
|
|
2015-10-12 09:24:18 +02:00
|
|
|
// `history.listen` is called on every route change, which is perfect for
|
|
|
|
// us in that case.
|
2015-10-01 15:17:55 +02:00
|
|
|
history.listen(EventActions.routeDidChange);
|
|
|
|
|
2015-09-30 17:09:46 +02:00
|
|
|
React.render((
|
|
|
|
<Router history={history}>
|
2015-10-01 15:57:46 +02:00
|
|
|
{redirectRoute}
|
2015-09-30 17:09:46 +02:00
|
|
|
{getRoutes(type, subdomain)}
|
|
|
|
</Router>
|
|
|
|
), document.getElementById('main'));
|
|
|
|
|
|
|
|
// Send the applicationDidBoot event to the third-party stores
|
2015-07-27 18:06:02 +02:00
|
|
|
EventActions.applicationDidBoot(settings);
|
2015-07-10 16:43:35 +02:00
|
|
|
}
|
2016-01-04 13:14:50 +01:00
|
|
|
};
|
2015-07-10 16:43:35 +02:00
|
|
|
|
2016-01-04 13:14:50 +01:00
|
|
|
// Initialize pre-start components
|
|
|
|
initLogging();
|
|
|
|
|
|
|
|
requests.defaults({
|
|
|
|
urlMap: ApiUrls,
|
|
|
|
http: {
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
credentials: 'include'
|
|
|
|
}
|
|
|
|
});
|
2015-07-17 15:41:09 +02:00
|
|
|
|
2016-01-04 13:14:50 +01:00
|
|
|
// And bootstrap app
|
|
|
|
AppGateway.start();
|