mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
Use distinct routers for different apps
This commit is contained in:
parent
cbe3be6faa
commit
d5ea4e515d
40
js/app.js
40
js/app.js
@ -8,7 +8,7 @@ import Router from 'react-router';
|
|||||||
import fetch from 'isomorphic-fetch';
|
import fetch from 'isomorphic-fetch';
|
||||||
|
|
||||||
import ApiUrls from './constants/api_urls';
|
import ApiUrls from './constants/api_urls';
|
||||||
import routes from './routes';
|
import getRoutes from './routes';
|
||||||
import requests from './utils/requests';
|
import requests from './utils/requests';
|
||||||
|
|
||||||
let headers = {
|
let headers = {
|
||||||
@ -28,9 +28,35 @@ requests.defaults({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.run(routes, Router.HistoryLocation, (AscribeApp) => {
|
|
||||||
React.render(
|
class AppGateway {
|
||||||
<AscribeApp />,
|
|
||||||
document.getElementById('main')
|
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
25
js/components/routes.js
Normal 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;
|
24
js/components/whitelabel/prize/app.js
Normal file
24
js/components/whitelabel/prize/app.js
Normal 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;
|
15
js/components/whitelabel/prize/components/landing.js
Normal file
15
js/components/whitelabel/prize/components/landing.js
Normal 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;
|
26
js/components/whitelabel/prize/routes.js
Normal file
26
js/components/whitelabel/prize/routes.js
Normal 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;
|
27
js/routes.js
27
js/routes.js
@ -4,6 +4,10 @@ import React from 'react';
|
|||||||
import Router from 'react-router';
|
import Router from 'react-router';
|
||||||
|
|
||||||
import AscribeApp from './components/ascribe_app';
|
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 PieceList from './components/piece_list';
|
||||||
import PieceContainer from './components/ascribe_detail/piece_container';
|
import PieceContainer from './components/ascribe_detail/piece_container';
|
||||||
import EditionContainer from './components/ascribe_detail/edition_container';
|
import EditionContainer from './components/ascribe_detail/edition_container';
|
||||||
@ -22,8 +26,9 @@ let Route = Router.Route;
|
|||||||
let Redirect = Router.Redirect;
|
let Redirect = Router.Redirect;
|
||||||
let baseUrl = AppConstants.baseUrl;
|
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="signup" path="signup" handler={SignupContainer} />
|
||||||
<Route name="login" path="login" handler={LoginContainer} />
|
<Route name="login" path="login" handler={LoginContainer} />
|
||||||
<Route name="pieces" path="collection" handler={PieceList} />
|
<Route name="pieces" path="collection" handler={PieceList} />
|
||||||
@ -33,10 +38,20 @@ let routes = (
|
|||||||
<Route name="register_piece" path="register_piece" handler={RegisterPiece} />
|
<Route name="register_piece" path="register_piece" handler={RegisterPiece} />
|
||||||
<Route name="settings" path="settings" handler={SettingsContainer} />
|
<Route name="settings" path="settings" handler={SettingsContainer} />
|
||||||
<Route name="coa_verify" path="verify" handler={CoaVerifyContainer} />
|
<Route name="coa_verify" path="verify" handler={CoaVerifyContainer} />
|
||||||
|
|
||||||
<Redirect from={baseUrl} to="login" />
|
|
||||||
<Redirect from={baseUrl + '/'} to="login" />
|
|
||||||
</Route>
|
</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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user