2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-06-19 15:17:44 +09:00
|
|
|
import { Messages } from 'meteor/nova:core';
|
2016-06-23 15:16:32 +09:00
|
|
|
import Events from "meteor/nova:events";
|
2016-11-26 02:46:55 +08:00
|
|
|
import { ReactRouterSSR } from 'meteor/reactrouter:react-router-ssr';
|
|
|
|
import React from 'react';
|
2016-06-29 09:15:52 +02:00
|
|
|
import Helmet from 'react-helmet';
|
2016-08-17 18:13:19 +02:00
|
|
|
import Cookie from 'react-cookie';
|
2016-08-25 09:54:24 +09:00
|
|
|
import ReactDOM from 'react-dom';
|
2016-11-26 02:46:55 +08:00
|
|
|
// import {mount} from 'react-mounter';
|
|
|
|
// import { IndexRoute, Route, useRouterHistory, browserHistory, createMemoryHistory } from 'react-router';
|
|
|
|
// import { ListContainer, DocumentContainer } from "meteor/utilities:react-list-container";
|
|
|
|
// import useNamedRoutes from 'use-named-routes';
|
|
|
|
// import createBrowserHistory from 'history/lib/createBrowserHistory';
|
2016-06-10 19:19:32 +09:00
|
|
|
|
2016-07-24 19:05:21 +09:00
|
|
|
Telescope.routes.indexRoute = { name: "posts.list", component: Telescope.components.PostsHome };
|
2016-06-10 19:19:32 +09:00
|
|
|
|
2016-06-15 11:07:30 +09:00
|
|
|
Meteor.startup(() => {
|
2016-06-11 16:36:18 +09:00
|
|
|
|
2016-06-15 11:07:30 +09:00
|
|
|
Telescope.routes.add([
|
2016-10-28 21:22:17 -07:00
|
|
|
{name:"posts.daily", path:"daily", component:Telescope.components.PostsDaily},
|
|
|
|
{name:"posts.single", path:"posts/:_id(/:slug)", component:Telescope.components.PostsSingle},
|
|
|
|
{name:"users.single", path:"users/:slug", component:Telescope.components.UsersSingle},
|
|
|
|
{name:"users.account", path:"account", component:Telescope.components.UsersAccount},
|
|
|
|
{name:"resetPassword", path:"reset-password/:token", component:Telescope.components.UsersResetPassword},
|
|
|
|
{name:"users.edit", path:"users/:slug/edit", component:Telescope.components.UsersAccount},
|
|
|
|
{name:"app.notfound", path:"*", component:Telescope.components.Error404},
|
2016-06-15 11:07:30 +09:00
|
|
|
]);
|
2016-06-13 16:02:27 +09:00
|
|
|
|
2016-06-15 11:07:30 +09:00
|
|
|
const AppRoutes = {
|
|
|
|
path: '/',
|
|
|
|
component: Telescope.components.App,
|
2016-07-24 19:05:21 +09:00
|
|
|
indexRoute: Telescope.routes.indexRoute,
|
2016-06-15 11:07:30 +09:00
|
|
|
childRoutes: Telescope.routes.routes
|
|
|
|
}
|
2016-06-14 10:01:44 +09:00
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
// let history;
|
2016-06-12 12:11:05 +09:00
|
|
|
|
2016-08-17 18:13:19 +02:00
|
|
|
const clientOptions = {
|
2016-08-25 09:54:24 +09:00
|
|
|
renderHook: ReactDOM.render,
|
2016-08-17 18:13:19 +02:00
|
|
|
props: {
|
|
|
|
onUpdate: () => {
|
2016-11-26 02:46:55 +08:00
|
|
|
Events.analyticsRequest();
|
2016-08-17 18:13:19 +02:00
|
|
|
Messages.clearSeen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-06-12 12:11:05 +09:00
|
|
|
|
2016-08-17 18:13:19 +02:00
|
|
|
const serverOptions = {
|
|
|
|
htmlHook: (html) => {
|
|
|
|
const head = Helmet.rewind();
|
2016-11-26 02:46:55 +08:00
|
|
|
return html.replace('<head>', '<head>'+ head.title + head.meta + head.link);
|
2016-08-17 18:13:19 +02:00
|
|
|
},
|
|
|
|
preRender: (req, res) => {
|
|
|
|
Cookie.plugToRequest(req, res);
|
|
|
|
},
|
|
|
|
};
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-08-17 18:13:19 +02:00
|
|
|
ReactRouterSSR.Run(AppRoutes, clientOptions, serverOptions);
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-08-17 18:13:19 +02:00
|
|
|
// note: we did like this at first
|
2016-06-21 18:07:47 +09:00
|
|
|
// if (Meteor.isClient) {
|
|
|
|
// history = useNamedRoutes(useRouterHistory(createBrowserHistory))({ routes: AppRoutes });
|
|
|
|
// }
|
|
|
|
// if (Meteor.isServer) {
|
|
|
|
// history = useNamedRoutes(useRouterHistory(createMemoryHistory))({ routes: AppRoutes });
|
|
|
|
// }
|
2016-06-15 11:07:30 +09:00
|
|
|
// ReactRouterSSR.Run(AppRoutes, {historyHook: () => history}, {historyHook: () => history});
|
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
});
|