1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00
onion/js/app.js

96 lines
2.9 KiB
JavaScript
Raw Normal View History

2015-05-13 16:26:12 +02:00
'use strict';
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';
import { Router, Redirect } from 'react-router';
import history from './history';
2015-06-01 14:22:04 +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';
import AppConstants from './constants/application_constants';
import getRoutes from './routes';
import requests from './utils/requests';
2015-06-01 14:22:04 +02:00
import { updateApiUrls } from './constants/api_urls';
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';
2015-07-17 15:41:09 +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
// import DebugHandler from './third_party/debug_handler';
import NotificationsHandler from './third_party/notifications_handler';
2015-05-20 11:23:50 +02:00
const AppGateway = {
start() {
try {
const subdomain = getSubdomain();
const settings = getSubdomainSettings(subdomain);
AppConstants.whitelabel = settings;
2015-07-14 21:15:10 +02:00
updateApiUrls(settings.type, subdomain);
this.load(settings);
} catch(err) {
// if there are no matching subdomains, we're routing
// to the default frontend
console.logGlobal(err);
this.load(getDefaultSubdomainSettings());
}
},
load(settings) {
const { subdomain, type } = settings;
2015-10-01 15:57:46 +02:00
let redirectRoute = (<Redirect from="/" to="/collection" />);
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') {
redirectRoute = null;
}
2015-09-21 16:23:18 +02: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
}
// Send the applicationWillBoot event to the third-party stores
EventActions.applicationWillBoot(settings);
2015-10-12 09:24:18 +02:00
// `history.listen` is called on every route change, which is perfect for
// us in that case.
history.listen(EventActions.routeDidChange);
React.render((
<Router history={history}>
2015-10-01 15:57:46 +02:00
{redirectRoute}
{getRoutes(type, subdomain)}
</Router>
), document.getElementById('main'));
// Send the applicationDidBoot event to the third-party stores
EventActions.applicationDidBoot(settings);
}
};
// 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
// And bootstrap app
AppGateway.start();