2016-06-02 15:24:16 +02:00
|
|
|
import 'core-js/es6';
|
|
|
|
import 'core-js/stage/4';
|
2016-01-05 13:38:58 +01:00
|
|
|
import 'classlist-polyfill';
|
2016-06-02 15:24:16 +02:00
|
|
|
import 'isomorphic-fetch';
|
2015-07-03 10:40:04 +02:00
|
|
|
|
2015-05-13 16:26:12 +02:00
|
|
|
import React from 'react';
|
2016-01-25 13:33:20 +01:00
|
|
|
import ReactDOM from 'react-dom';
|
2016-06-06 14:54:29 +02:00
|
|
|
import Router from 'react-router/es6/Router';
|
2015-06-01 14:22:04 +02:00
|
|
|
|
2016-06-03 17:52:38 +02:00
|
|
|
import AppResolver from './app_resolver';
|
|
|
|
import history from './history';
|
2015-06-01 14:22:04 +02:00
|
|
|
|
2016-06-06 15:40:26 +02:00
|
|
|
import AppConstants from './constants/application_constants';
|
|
|
|
|
2016-06-13 14:35:02 +02:00
|
|
|
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants';
|
|
|
|
import { initLogging } from './utils/error';
|
2016-06-13 17:33:47 +02:00
|
|
|
import { getCurrentSubdomain } from './utils/url';
|
2016-06-14 13:05:57 +02:00
|
|
|
import UrlResolver from './utils/url_resolver';
|
2015-07-17 15:41:09 +02:00
|
|
|
|
2016-06-06 15:40:26 +02:00
|
|
|
|
2016-06-03 17:52:38 +02:00
|
|
|
// FIXME: rename these event actions
|
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';
|
2016-06-02 15:24:16 +02:00
|
|
|
import './third_party/facebook_handler';
|
|
|
|
import './third_party/ga_handler';
|
|
|
|
import './third_party/intercom_handler';
|
|
|
|
import './third_party/notifications_handler';
|
|
|
|
import './third_party/raven_handler';
|
|
|
|
|
|
|
|
// Import global stylesheet
|
|
|
|
import '../sass/main.scss';
|
2015-07-27 18:06:02 +02:00
|
|
|
|
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() {
|
2016-06-03 17:52:38 +02:00
|
|
|
let subdomainSettings;
|
|
|
|
|
2015-07-14 17:12:32 +02:00
|
|
|
try {
|
2016-06-13 17:33:47 +02:00
|
|
|
subdomainSettings = getSubdomainSettings(getCurrentSubdomain());
|
2016-06-03 17:52:38 +02:00
|
|
|
} catch (err) {
|
|
|
|
// if there are no matching subdomains, we''ll route to the default frontend
|
2015-07-17 15:52:53 +02:00
|
|
|
console.logGlobal(err);
|
2016-06-03 17:52:38 +02:00
|
|
|
subdomainSettings = getDefaultSubdomainSettings();
|
2015-07-14 17:12:32 +02:00
|
|
|
}
|
2016-06-03 17:52:38 +02:00
|
|
|
|
|
|
|
this.load(subdomainSettings);
|
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) {
|
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
|
|
|
|
2016-06-03 17:52:38 +02:00
|
|
|
// `history.listen` is called on every route change, which is perfect for routeDidChange
|
|
|
|
// events.
|
2016-06-06 15:40:26 +02:00
|
|
|
// For history <= 3.0, history.listen will synchronously invoke the callback once
|
|
|
|
// immediately after registration.
|
|
|
|
history.listen((location) => {
|
|
|
|
const { locationQueue } = history;
|
|
|
|
locationQueue.unshift(location);
|
|
|
|
|
|
|
|
// Limit the number of locations to keep in memory to avoid too much memory usage
|
|
|
|
if (locationQueue.length > AppConstants.locationThreshold) {
|
|
|
|
locationQueue.length = AppConstants.locationThreshold;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventActions.routeDidChange(location);
|
|
|
|
});
|
2015-10-01 15:17:55 +02:00
|
|
|
|
2016-06-03 17:52:38 +02:00
|
|
|
// Adds a client specific class to the body for whitelabel styling
|
2016-06-06 16:05:18 +02:00
|
|
|
window.document.body.classList.add(`client--${settings.subdomain || 'ascribe'}`);
|
2016-06-03 17:52:38 +02:00
|
|
|
|
|
|
|
AppResolver
|
|
|
|
.resolve(settings)
|
|
|
|
.then(({ apiUrls, redirectRoute, routes }) => {
|
2016-06-14 13:05:57 +02:00
|
|
|
// Set url mapping for outgoing api requests
|
|
|
|
UrlResolver.setUrlMapping(apiUrls);
|
2016-06-03 17:52:38 +02:00
|
|
|
|
2016-01-25 13:33:20 +01:00
|
|
|
ReactDOM.render((
|
2016-06-03 17:52:38 +02:00
|
|
|
<Router history={history}>
|
|
|
|
{redirectRoute}
|
|
|
|
{routes}
|
|
|
|
</Router>
|
|
|
|
), document.getElementById('main'));
|
|
|
|
|
|
|
|
// Send the applicationDidBoot event to the third-party stores
|
|
|
|
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();
|
|
|
|
|
|
|
|
// And bootstrap app
|
|
|
|
AppGateway.start();
|