<commit_before>import React from 'react'
import { RoutingContext, match } from 'react-router'
import { getPrefetchedData } from 'react-fetcher'
import { store } from 'app/state/store'
import { history } from 'app/state/history'

export default function(makeRoutes) {
  return function *(next) {
    const routes = makeRoutes()
    const location = history.createLocation(this.request.url)
    yield new Promise(resolve => {
      match({ routes, location }, async (error, redirect, renderProps) => {
        if (redirect)
          return this.redirect(redirect.pathname + redirect.search)
        else if (error)
          return this.throw(error.message)
        else if (renderProps == null)
          return this.throw(404, 'Not found')
        const locals = {
          store,
          location: renderProps.location,
          params: renderProps.params,
        }
        await getPrefetchedData(renderProps.components, locals)
        this.routeContext = <RoutingContext {...renderProps} />
        resolve()
      })
    })
    yield next
  }
}<commit_msg>making use of promise to get routeContext in server middleware<commit_after>import React from 'react'
import { RoutingContext, match } from 'react-router'
import { getPrefetchedData } from 'react-fetcher'
import { store } from 'app/state/store'
import { history } from 'app/state/history'

export default function(makeRoutes) {
  return function *(next) {
    const routes = makeRoutes()
    const location = history.createLocation(this.request.url)
    this.routeContext = yield new Promise(resolve => {
      match({ routes, location }, async (error, redirect, renderProps) => {
        if (redirect)
          return this.redirect(redirect.pathname + redirect.search)
        else if (error)
          return this.throw(error.message)
        else if (renderProps == null)
          return this.throw(404, 'Not found')
        await getPrefetchedData(renderProps.components, {
          store,
          location: renderProps.location,
          params: renderProps.params,
        })
        resolve(<RoutingContext {...renderProps} />)
      })
    })
    yield next
  }
}
{'fraction_non_alphanumeric': 0.10774253731343283, 'fraction_numerical': 0.002798507462686567, 'mean_word_length': 2.7964601769911503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '660380', 'n_tokens_mistral': 584, 'n_tokens_neox': 581, 'n_words': 159}