Last active
November 3, 2015 19:27
-
-
Save lesniakania/836220de90fc8e98c1fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
import { configureStore } from './src/Store'; | |
import { ReduxRouter } from 'redux-router'; | |
import { reduxReactRouter, match } from 'redux-router/server'; | |
import { Provider } from 'react-redux'; | |
import createHistory from 'history/lib/createMemoryHistory'; | |
// ... | |
app.use((request, response) => { | |
const initialState = {}; | |
const store = configureStore(initialState, createHistory, | |
reduxReactRouter); | |
store.dispatch(match(request.originalUrl, | |
(error, redirectLocation, routerState) => { | |
if (error) { | |
response.status(500).send(error.message); | |
} else if (redirectLocation) { | |
response.redirect(302, redirectLocation.pathname + redirectLocation.search); | |
} else if (routerState) { | |
response.render('index', { | |
isDevelopment: isDevelopment, | |
app: ReactDOMServer.renderToString( | |
<Provider store={store}> | |
<ReduxRouter/> | |
</Provider> | |
) | |
}); | |
} else { | |
response.status(404).send('Not found'); | |
} | |
})); | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment