Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Last active August 10, 2017 10:13
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/359dcfe3ade870ffdc16011111b771fc to your computer and use it in GitHub Desktop.
Save faceyspacey/359dcfe3ade870ffdc16011111b771fc to your computer and use it in GitHub Desktop.
const { ...theUsual, thunk, initialDispatch } = connectRoutes(
history,
routesMap, {
...options,
initialDispatch: isServer ? false : true
}
)
...
return { store, thunk, initialDispatch }
import { fetchUser } from '../src/actions/async'
export default async (req, res) => {
const history = createHistory({ initialEntries: [req.path] })
const { store, thunk, initialDispatch } = configureStore(history)
await store.dispatch(fetchUser(req.cookies.sessionId))
initialDispatch()
if (doesRedirect(store.getState().location, res)) return false
await thunk(store)
if (doesRedirect(store.getState().location, res)) return false
const status = location.type === NOT_FOUND ? 404 : 200
res.status(status)
return store
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment