Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Created August 10, 2017 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faceyspacey/476485296548b0be41aa47b95e680801 to your computer and use it in GitHub Desktop.
Save faceyspacey/476485296548b0be41aa47b95e680801 to your computer and use it in GitHub Desktop.
import createHistory from 'history/createMemoryHistory'
import { NOT_FOUND } from 'redux-first-router'
import configureStore from '../src/configureStore'
export default async (req, res) => {
const history = createHistory({ initialEntries: [req.path] })
const { store, thunk } = configureStore(history)
await thunk(store) // THE PAYOFF!
let location = store.getState().location
if (doesRedirect(location, res)) return false
const status = location.type === NOT_FOUND ? 404 : 200
res.status(status)
return store
}
const doesRedirect = ({ kind, pathname }, res) => {
if (kind === 'redirect') {
res.redirect(302, pathname)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment