1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/app.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

import 'core-js/es6';
import 'core-js/stage/4';
2016-01-05 13:38:58 +01:00
import 'classlist-polyfill';
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-03 17:52:38 +02:00
import { Router } from 'react-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
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils';
2015-07-17 15:41:09 +02:00
import { initLogging } from './utils/error_utils';
import { getSubdomain } from './utils/general_utils';
2016-06-03 17:52:38 +02:00
import requests from './utils/requests';
2015-07-17 15:41:09 +02:00
2016-06-03 17:52:38 +02:00
// FIXME: rename these event actions
import EventActions from './actions/event_actions';
2015-07-27 18:21:20 +02:00
// You can comment out the modules you don't need
// import DebugHandler from './third_party/debug_handler';
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-05-20 11:23:50 +02:00
const AppGateway = {
start() {
2016-06-03 17:52:38 +02:00
let subdomainSettings;
try {
2016-06-03 17:52:38 +02:00
subdomainSettings = getSubdomainSettings(getSubdomain());
} catch (err) {
// if there are no matching subdomains, we''ll route to the default frontend
console.logGlobal(err);
2016-06-03 17:52:38 +02:00
subdomainSettings = getDefaultSubdomainSettings();
}
2016-06-03 17:52:38 +02:00
this.load(subdomainSettings);
},
load(settings) {
// Send the applicationWillBoot event to the third-party stores
EventActions.applicationWillBoot(settings);
2016-06-03 17:52:38 +02:00
// `history.listen` is called on every route change, which is perfect for routeDidChange
// events.
history.listen(EventActions.routeDidChange);
2016-06-03 17:52:38 +02:00
// Adds a client specific class to the body for whitelabel styling
window.document.body.classList.add(`client--${settings.subdomain}`);
AppResolver
.resolve(settings)
.then(({ apiUrls, redirectRoute, routes }) => {
// Initialize api urls and defaults for outgoing requests
requests.defaults({
urlMap: apiUrls,
http: {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
credentials: 'include'
}
});
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);
});
}
};
// Initialize pre-start components
initLogging();
// And bootstrap app
AppGateway.start();