1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

Use distinct routers for different apps

This commit is contained in:
vrde 2015-07-10 16:43:35 +02:00
parent cbe3be6faa
commit d5ea4e515d
6 changed files with 144 additions and 13 deletions

View File

@ -8,7 +8,7 @@ import Router from 'react-router';
import fetch from 'isomorphic-fetch';
import ApiUrls from './constants/api_urls';
import routes from './routes';
import getRoutes from './routes';
import requests from './utils/requests';
let headers = {
@ -28,9 +28,35 @@ requests.defaults({
}
});
Router.run(routes, Router.HistoryLocation, (AscribeApp) => {
React.render(
<AscribeApp />,
document.getElementById('main')
);
});
class AppGateway {
start() {
let subdomain = window.location.host.split('.')[0];
requests.get('whitelabel_settings', {'subdomain': subdomain})
.then(this.loadSubdomain.bind(this))
.catch(this.loadDefault.bind(this));
}
loadSubdomain(data) {
let settings = data.whitelabel;
this.load('prize');
}
loadDefault() {
this.load('default');
}
load(type) {
Router.run(getRoutes(type), Router.HistoryLocation, (App) => {
React.render(
<App />,
document.getElementById('main')
);
});
}
}
let ag = new AppGateway();
ag.start();

25
js/components/routes.js Normal file
View File

@ -0,0 +1,25 @@
'use strict';
import React from 'react';
import Router from 'react-router';
import App from './ascribe_app';
import AppConstants from '../constants/application_constants';
let Route = Router.Route;
let Redirect = Router.Redirect;
let baseUrl = AppConstants.baseUrl;
function getRoutes(commonRoutes) {
return (
<Route name="app" path={baseUrl} handler={App}>
{commonRoutes}
<Redirect from={baseUrl} to="login" />
<Redirect from={baseUrl + '/'} to="login" />
</Route>
);
}
export default getRoutes;

View File

@ -0,0 +1,24 @@
'use strict';
import React from 'react';
import Router from 'react-router';
import Footer from '../../footer';
import GlobalNotification from '../../global_notification';
let RouteHandler = Router.RouteHandler;
let PrizeApp = React.createClass({
render() {
return (
<div>
<RouteHandler />
<Footer />
<GlobalNotification />
<div id="modal" className="container"></div>
</div>
);
}
});
export default PrizeApp;

View File

@ -0,0 +1,15 @@
'use strict';
import React from 'react';
let Landing = React.createClass({
render() {
return (
<div>
Hello from landing
</div>
);
}
});
export default Landing;

View File

@ -0,0 +1,26 @@
'use strict';
import React from 'react';
import Router from 'react-router';
import Landing from './components/landing';
import App from './app';
import AppConstants from '../../../constants/application_constants';
let Route = Router.Route;
// let Redirect = Router.Redirect;
let baseUrl = AppConstants.baseUrl;
function getRoutes(commonRoutes) {
return (
<Route name="app" path={baseUrl} handler={App}>
<Route name="landing" path="/" handler={Landing} />
{commonRoutes}
</Route>
);
}
export default getRoutes;

View File

@ -4,6 +4,10 @@ import React from 'react';
import Router from 'react-router';
import AscribeApp from './components/ascribe_app';
import getPrizeRoutes from './components/whitelabel/prize/routes';
import getDefaultRoutes from './components/routes';
import PieceList from './components/piece_list';
import PieceContainer from './components/ascribe_detail/piece_container';
import EditionContainer from './components/ascribe_detail/edition_container';
@ -22,8 +26,9 @@ let Route = Router.Route;
let Redirect = Router.Redirect;
let baseUrl = AppConstants.baseUrl;
let routes = (
<Route name="app" path={baseUrl} handler={AscribeApp}>
const COMMON_ROUTES = (
<Route>
<Route name="signup" path="signup" handler={SignupContainer} />
<Route name="login" path="login" handler={LoginContainer} />
<Route name="pieces" path="collection" handler={PieceList} />
@ -33,10 +38,20 @@ let routes = (
<Route name="register_piece" path="register_piece" handler={RegisterPiece} />
<Route name="settings" path="settings" handler={SettingsContainer} />
<Route name="coa_verify" path="verify" handler={CoaVerifyContainer} />
<Redirect from={baseUrl} to="login" />
<Redirect from={baseUrl + '/'} to="login" />
</Route>
);
export default routes;
function getRoutes(type) {
let routes = null;
if (type === 'prize') {
routes = getPrizeRoutes(COMMON_ROUTES);
} else {
routes = getDefaultRoutes(COMMON_ROUTES);
}
return routes;
}
export default getRoutes;