2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-04-22 10:46:09 +09:00
|
|
|
import React from 'react';
|
2016-06-19 15:17:44 +09:00
|
|
|
import { Messages } from 'meteor/nova:core';
|
2016-06-12 12:11:05 +09:00
|
|
|
import { IndexRoute, Route, useRouterHistory, browserHistory, createMemoryHistory } from 'react-router';
|
2016-06-10 19:19:32 +09:00
|
|
|
import { ReactRouterSSR } from 'meteor/reactrouter:react-router-ssr';
|
2016-06-12 12:11:05 +09:00
|
|
|
import createBrowserHistory from 'history/lib/createBrowserHistory';
|
2016-06-23 15:16:32 +09:00
|
|
|
import Events from "meteor/nova:events";
|
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-06-10 19:19:32 +09:00
|
|
|
|
2016-10-19 10:55:19 +02:00
|
|
|
import { ApolloProvider } from 'react-apollo';
|
2016-10-28 18:09:41 +02:00
|
|
|
import { client } from 'meteor/nova:base-apollo';
|
|
|
|
import { store } from "./store.js";
|
2016-10-19 10:32:24 +02: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-07-27 13:06:57 +09:00
|
|
|
{name:"posts.daily", path:"daily", component:Telescope.components.PostsDaily},
|
2016-06-15 11:07:30 +09:00
|
|
|
{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},
|
2016-09-16 16:14:23 +02:00
|
|
|
{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-10-19 10:32:24 +02:00
|
|
|
|
|
|
|
const ProvidedApp = (props) => (
|
2016-10-19 10:55:19 +02:00
|
|
|
<ApolloProvider store={store} client={client}>
|
2016-10-28 15:45:43 +09:00
|
|
|
<Telescope.components.AppContainer {...props} />
|
2016-10-19 10:55:19 +02:00
|
|
|
</ApolloProvider>
|
2016-10-19 10:32:24 +02:00
|
|
|
);
|
2016-06-13 16:02:27 +09:00
|
|
|
|
2016-06-15 11:07:30 +09:00
|
|
|
const AppRoutes = {
|
|
|
|
path: '/',
|
2016-10-19 10:32:24 +02:00
|
|
|
component: ProvidedApp,
|
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-10-19 10:32:24 +02:00
|
|
|
};
|
2016-06-14 10:01:44 +09:00
|
|
|
|
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: () => {
|
|
|
|
Events.analyticsRequest();
|
2016-10-31 17:13:14 +01:00
|
|
|
// clear all previous messages
|
|
|
|
store.dispatch(Telescope.actions.messages.clearSeen());
|
|
|
|
},
|
|
|
|
},
|
2016-08-17 18:13:19 +02:00
|
|
|
};
|
2016-06-12 12:11:05 +09:00
|
|
|
|
2016-08-17 18:13:19 +02:00
|
|
|
const serverOptions = {
|
|
|
|
htmlHook: (html) => {
|
|
|
|
const head = Helmet.rewind();
|
|
|
|
return html.replace('<head>', '<head>'+ head.title + head.meta + head.link);
|
|
|
|
},
|
|
|
|
preRender: (req, res) => {
|
|
|
|
Cookie.plugToRequest(req, res);
|
|
|
|
},
|
2016-10-19 10:55:19 +02:00
|
|
|
// see https://github.com/thereactivestack/meteor-react-router-ssr/blob/9762f12c5d5512c5cfee8663a29428f7e4c141f8/lib/server.jsx#L241-L257
|
|
|
|
fetchDataHook: (components) => {
|
|
|
|
console.log('this is where ssr & apollo should interact')
|
|
|
|
return [new Promise((resolve, reject) => {
|
|
|
|
resolve();
|
|
|
|
})];
|
|
|
|
},
|
2016-08-17 18:13:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReactRouterSSR.Run(AppRoutes, clientOptions, serverOptions);
|
|
|
|
|
|
|
|
// note: we did like this at first
|
2016-10-19 10:55:19 +02:00
|
|
|
// let history;
|
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});
|
|
|
|
|
|
|
|
});
|