From c50510db71e8ccb4ac31188707248f936f17d272 Mon Sep 17 00:00:00 2001
From: Berkeley Martinez <Berkeley@robotie.com>
Date: Wed, 2 Mar 2016 19:45:54 -0800
Subject: [PATCH] Update history/react-router

---
 client/index.js                                |  4 ++--
 common/app/create-app.jsx                      |  8 ++++----
 common/app/routes/Jobs/components/JobTotal.jsx |  2 +-
 common/app/routes/Jobs/components/Preview.jsx  |  2 +-
 package.json                                   |  6 +++---
 server/boot/a-react.js                         | 15 +++++++--------
 server/services/job.js                         |  1 -
 7 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/client/index.js b/client/index.js
index 92d4d9c..0925a6c 100644
--- a/client/index.js
+++ b/client/index.js
@@ -4,7 +4,7 @@ import React from 'react';
 import debug from 'debug';
 import { Router } from 'react-router';
 import { routeReducer as routing, syncHistory } from 'react-router-redux';
-import { createLocation, createHistory } from 'history';
+import { createHistory } from 'history';
 
 import app$ from '../common/app';
 import provideStore from '../common/app/provide-store';
@@ -23,7 +23,7 @@ const serviceOptions = { xhrPath: '/services' };
 
 Rx.config.longStackSupport = !!debug.enabled;
 const history = createHistory();
-const appLocation = createLocation(
+const appLocation = history.createLocation(
   location.pathname + location.search
 );
 const routingMiddleware = syncHistory(history);
diff --git a/common/app/create-app.jsx b/common/app/create-app.jsx
index 27a6cd2..f07a830 100644
--- a/common/app/create-app.jsx
+++ b/common/app/create-app.jsx
@@ -21,7 +21,7 @@ const routes = { components: App, ...childRoutes };
 
 //
 // createApp(settings: {
-//   location?: Location,
+//   location?: Location|String,
 //   history?: History,
 //   initialState?: Object|Void,
 //   serviceOptions?: Object,
@@ -65,13 +65,13 @@ export default function createApp({
   const store = compose(...enhancers)(createStore)(reducer, initialState);
 
   // createRouteProps({
-  //   location: LocationDescriptor,
+  //   redirect: LocationDescriptor,
   //   history: History,
   //   routes: Object
   // }) => Observable
   return createRouteProps({ routes, location, history })
-    .map(([ nextLocation, props ]) => ({
-      nextLocation,
+    .map(([ redirect, props ]) => ({
+      redirect,
       props,
       reducer,
       store
diff --git a/common/app/routes/Jobs/components/JobTotal.jsx b/common/app/routes/Jobs/components/JobTotal.jsx
index 9524d44..97b3db9 100644
--- a/common/app/routes/Jobs/components/JobTotal.jsx
+++ b/common/app/routes/Jobs/components/JobTotal.jsx
@@ -76,7 +76,7 @@ export class JobTotal extends PureComponent {
     promoApplied: PropTypes.bool
   };
 
-  componentDidMount() {
+  componentWillMount() {
     if (!this.props.id) {
       this.props.push('/jobs');
     }
diff --git a/common/app/routes/Jobs/components/Preview.jsx b/common/app/routes/Jobs/components/Preview.jsx
index 478b3cf..7509408 100644
--- a/common/app/routes/Jobs/components/Preview.jsx
+++ b/common/app/routes/Jobs/components/Preview.jsx
@@ -34,7 +34,7 @@ export class JobPreview extends PureComponent {
     push: PropTypes.func
   };
 
-  componentDidMount() {
+  componentWillMount() {
     const { push, job } = this.props;
     // redirect user in client
     if (!job || !job.position || !job.description) {
diff --git a/package.json b/package.json
index 15e4d5a..62d49b1 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,7 @@
     "gulp-util": "^3.0.6",
     "helmet": "^1.1.0",
     "helmet-csp": "^1.0.3",
-    "history": "^1.17.0",
+    "history": "^2.0.0",
     "jade": "^1.11.0",
     "json-loader": "~0.5.2",
     "less": "^2.5.1",
@@ -108,8 +108,8 @@
     "react-motion": "~0.4.2",
     "react-pure-render": "^1.0.2",
     "react-redux": "^4.0.6",
-    "react-router": "^1.0.0",
-    "react-router-bootstrap": "https://github.com/FreeCodeCamp/react-router-bootstrap.git#freecodecamp",
+    "react-router": "^2.0.0",
+    "react-router-bootstrap": "~0.20.1",
     "react-toastr": "^2.4.0",
     "react-router-redux": "^2.1.0",
     "react-vimeo": "~0.1.0",
diff --git a/server/boot/a-react.js b/server/boot/a-react.js
index 009e585..5d13e39 100644
--- a/server/boot/a-react.js
+++ b/server/boot/a-react.js
@@ -1,6 +1,5 @@
 import React from 'react';
-import { RoutingContext } from 'react-router';
-import { createLocation } from 'history';
+import { RouterContext } from 'react-router';
 import debug from 'debug';
 
 import renderToString from '../../common/app/utils/render-to-string';
@@ -39,15 +38,15 @@ export default function reactSubRouter(app) {
 
   function serveReactApp(req, res, next) {
     const serviceOptions = { req };
-    const location = createLocation(req.path);
-
-    // returns a router wrapped app
     app$({
-      location,
+      location: req.path,
       serviceOptions
     })
       // if react-router does not find a route send down the chain
-      .filter(({ props }) => {
+      .filter(({ redirect, props }) => {
+        if (!props && redirect) {
+          res.redirect(redirect.pathname + redirect.search);
+        }
         if (!props) {
           log(`react tried to find ${location.pathname} but got 404`);
           return next();
@@ -58,7 +57,7 @@ export default function reactSubRouter(app) {
         log('render react markup and pre-fetch data');
 
         return renderToString(
-          provideStore(React.createElement(RoutingContext, props), store)
+          provideStore(React.createElement(RouterContext, props), store)
         )
           .map(({ markup }) => ({ markup, store }));
       })
diff --git a/server/services/job.js b/server/services/job.js
index e5fdf87..94e7ee2 100644
--- a/server/services/job.js
+++ b/server/services/job.js
@@ -28,7 +28,6 @@ export default function getJobServices(app) {
     },
     read(req, resource, params, config, cb) {
       const id = params ? params.id : null;
-      console.log('params', params);
       if (id) {
         return Job.findById(id)
           .then(job => cb(null, job.toJSON()))
