<commit_before>import chalk from "chalk";
import path from "path";
import { createElement } from "react";
import { renderToString } from "react-dom/server";
import { runBeforeRoutes, ROUTE_NAME_404_NOT_FOUND, prepareRoutesWithTransitionHooks } from "gluestick-shared";
import { match, RouterContext, Route } from "react-router";
import showHelpText, { MISSING_404_TEXT } from "../lib/help-text";
import logger from "./logger";

import serverErrorHandler from "./server-error-handler";
import Body from "../shared/components/Body";
import getHead from "../shared/components/getHead";

process.on("unhandledRejection", (reason, promise) => {
  console.log(chalk.red(reason), promise);
});

module.exports = async function (req, res) {
  try {
    const Index = require(path.join(process.cwd(), "Index")).default;
    const Entry = require(path.join(process.cwd(), "src/config/.entry")).default;
    const store = require(path.join(process.cwd(), "src/config/.store")).default();
    let originalRoutes = require(path.join(process.cwd(), "src/config/routes")).default;

    // @TODO: Remove this in the future when people have had enough time to
    // upgrade.  When this deprecation notice and backward compatibility check
    // are removed, remove from new/src/config/.entry as well
    if (typeof originalRoutes !== "function") {
      logger.warn(`
##########################################################################
Deprecation Notice: src/config/routes.js is expected to export a
function that returns the routes object, not the routes object
itself. This gives you access to the redux store so you can use it
in async react-router methods. For a simple example see:
https://github.com/TrueCar/gluestick/blob/develop/new/src/config/routes.js
##########################################################################
`);
      originalRoutes = () => originalRoutes;
    }

    const config = require(path.join(process.cwd(), "src/config/application")).default;
    const routes = prepareRoutesWithTransitionHooks(originalRoutes);
    match({routes: routes, location: req.path}, async (error, redirectLocation, renderProps) => {
      try {<commit_msg>fix server side routes<commit_after>import chalk from "chalk";
import path from "path";
import { createElement } from "react";
import { renderToString } from "react-dom/server";
import { runBeforeRoutes, ROUTE_NAME_404_NOT_FOUND, prepareRoutesWithTransitionHooks } from "gluestick-shared";
import { match, RouterContext, Route } from "react-router";
import showHelpText, { MISSING_404_TEXT } from "../lib/help-text";
import logger from "./logger";

import serverErrorHandler from "./server-error-handler";
import Body from "../shared/components/Body";
import getHead from "../shared/components/getHead";

process.on("unhandledRejection", (reason, promise) => {
  console.log(chalk.red(reason), promise);
});

module.exports = async function (req, res) {
  try {
    const Index = require(path.join(process.cwd(), "Index")).default;
    const Entry = require(path.join(process.cwd(), "src/config/.entry")).default;
    const store = require(path.join(process.cwd(), "src/config/.store")).default();
    let originalRoutes = require(path.join(process.cwd(), "src/config/routes")).default;

    // @TODO: Remove this in the future when people have had enough time to
    // upgrade.  When this deprecation notice and backward compatibility check
    // are removed, remove from new/src/config/.entry as well
    if (typeof originalRoutes !== "function") {
      logger.warn(`
##########################################################################
Deprecation Notice: src/config/routes.js is expected to export a
function that returns the routes object, not the routes object
itself. This gives you access to the redux store so you can use it
in async react-router methods. For a simple example see:
https://github.com/TrueCar/gluestick/blob/develop/new/src/config/routes.js
##########################################################################
`);
      originalRoutes = () => originalRoutes;
    }

    const config = require(path.join(process.cwd(), "src/config/application")).default;
    const routes = prepareRoutesWithTransitionHooks(originalRoutes(store));
    match({routes: routes, location: req.path}, async (error, redirectLocation, renderProps) => {
      try {
{'fraction_non_alphanumeric': 0.190234914785813, 'fraction_numerical': 0.0027637033625057578, 'mean_word_length': 4.884823848238482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3810612', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1181, 'n_words': 343}