<commit_before>/**
 * This is the main server entry point into the
 * react-router example.
 *
 * Inspired heavily from:
 * https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md
 */

import DOM from 'react-dom/server'
import React from 'react'
import Todos from './app/todos'
import routes from './app/components/routes'
import { match, RoutingContext } from 'react-router'

const basename = '/react-router'

export default function register (server, _options, next) {

  server.route({
    method  : 'GET',
    path    : '/{path*}',
    handler(request, reply) {
      let app = new Todos()

      let params = { basename, routes, location: request.raw.req.url }

      function createElement (Handler, state) {
        return (<Handler app={ app } { ...state } />)
      }

      app.start(function (error) {
        if (error) throw error

        match(params, function (error, redirect, props) {
          if (error) {
            return reply.view('server/error', new Error('wut')).code(500)
          }

          if (redirect) {
            return reply.redirect(redirect.pathname + redirect.search)
          }

          if (props) {
            return reply.view('apps/react-router/index', {
              markup  : DOM.renderToString(<RoutingContext createElement={ createElement } { ...props } />),
              payload : JSON.stringify(app)
            })
          }

          return reply('Page not found').code(404)
        })
      })
    }<commit_msg>Pass along the appropriate error<commit_after>/**
 * This is the main server entry point into the
 * react-router example.
 *
 * Inspired heavily from:
 * https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md
 */

import DOM from 'react-dom/server'
import React from 'react'
import Todos from './app/todos'
import routes from './app/components/routes'
import { match, RoutingContext } from 'react-router'

const basename = '/react-router'

export default function register (server, _options, next) {

  server.route({
    method  : 'GET',
    path    : '/{path*}',
    handler(request, reply) {
      let app = new Todos()

      let params = { basename, routes, location: request.raw.req.url }

      function createElement (Handler, state) {
        return (<Handler app={ app } { ...state } />)
      }

      app.start(function (error) {
        if (error) throw error

        match(params, function (error, redirect, props) {
          if (error) {
            return reply.view('server/error', error).code(500)
          }

          if (redirect) {
            return reply.redirect(redirect.pathname + redirect.search)
          }

          if (props) {
            return reply.view('apps/react-router/index', {
              markup  : DOM.renderToString(<RoutingContext createElement={ createElement } { ...props } />),
              payload : JSON.stringify(app)
            })
          }

          return reply('Page not found').code(404)
        })
      })
    }
{'fraction_non_alphanumeric': 0.13161375661375663, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 2.259698275862069, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5883030', 'n_tokens_mistral': 873, 'n_tokens_neox': 846, 'n_words': 223}