Skip to content

Instantly share code, notes, and snippets.

@lesniakania
Last active November 3, 2015 19:27
Show Gist options
  • Save lesniakania/836220de90fc8e98c1fb to your computer and use it in GitHub Desktop.
Save lesniakania/836220de90fc8e98c1fb to your computer and use it in GitHub Desktop.
// ...
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