import 'babel/polyfill'; import React from 'react'; import { Router } from 'react-router'; import BrowserHistory from 'react-router/lib/BrowserHistory'; import { Provider } from 'redux/react'; import createRedux from './redux/createRedux'; import { createRoutes } from './routes'; import getInitialState from './core/getInitialState'; import bindCheckAuth from './core/bindCheckAuth'; function run() { const reactRoot = window.document.getElementById('app'); const state = getInitialState('#__INITIAL_STATE__'); const redux = createRedux(state); const requireAccess = bindCheckAuth(redux, (nextState, transition) => { transition.to('/login', { next: nextState.location.pathname }); }, (nextState, transition) => { transition.to('/403'); }); const routes = createRoutes(requireAccess); const history = new BrowserHistory(); React.render(( {() => } ), reactRoot); if (process.env.NODE_ENV !== 'production') { window.React = React; // enable debugger if (!reactRoot || !reactRoot.firstChild || !reactRoot.firstChild.attributes || !reactRoot.firstChild.attributes['data-react-checksum']) { console.error('Server-side React render was discarded. Make sure that your initial render does not contain any client-side code.'); } } } // Run the application when both DOM is ready // and page content is loaded Promise.all([ new Promise((resolve) => { if (window.addEventListener) { window.addEventListener('DOMContentLoaded', resolve); } else { window.attachEvent('onload', resolve); } }) ]).then(run);