<commit_before>import React from "react"
import express, { Request } from "express"
import {
  buildServerApp,
  ServerAppResolve,
} from "@artsy/reaction/dist/Artsy/Router/server"
import { getAppRoutes } from "reaction/Apps/getAppRoutes"
import { stitch } from "@artsy/stitch"
import { buildServerAppContext } from "desktop/lib/buildServerAppContext"
import { SearchResultsSkeleton } from "reaction/Apps/Search/Components/SearchResultsSkeleton"
import { StitchWrapper } from "desktop/components/react/stitch_components/StitchWrapper"
import { artistMiddleware } from "./artist/middleware"
import { searchMiddleware } from "./search/middleware"
import { handleArtworkImageDownload } from "./artwork/middleware"

export const app = express()

// Non-Reaction routes
app.get("/artwork/:artworkID/download/:filename", handleArtworkImageDownload)

app.get(
  "/*",
  searchMiddleware,
  artistMiddleware,
  async (req: Request, res, next) => {
    try {
      const pageParts = req.path.split("/")
      const pageType = pageParts[1]
      let serverApp: ServerAppResolve = {}

      /**
       * Search intentionally bypasses SSR, but we still need to inject the
       * experimental-app-shell asset into the page. Because of bundle splitting
       * we now get that back dynamically from `buildServerApp` below.
       *
       * @see https://github.com/artsy/reaction/blob/master/src/Artsy/Router/buildServerApp.tsx#L157
       */
      if (pageType === "search") {
        const { CDN_URL = "" } = process.env
        serverApp.scripts = `<script async data-chunk="experimental-app-shell" src="${CDN_URL}/assets/experimental-app-shell.js"></script>`
      } else {
        serverApp = await buildServerApp({
          context: buildServerAppContext(req, res),<commit_msg>[Clientside Routing] Use assetMiddleware helper to return search script src<commit_after>import React from "react"
import express, { Request } from "express"
import {
  buildServerApp,
  ServerAppResolve,
} from "@artsy/reaction/dist/Artsy/Router/server"
import { getAppRoutes } from "reaction/Apps/getAppRoutes"
import { stitch } from "@artsy/stitch"
import { buildServerAppContext } from "desktop/lib/buildServerAppContext"
import { SearchResultsSkeleton } from "reaction/Apps/Search/Components/SearchResultsSkeleton"
import { StitchWrapper } from "desktop/components/react/stitch_components/StitchWrapper"
import { artistMiddleware } from "./artist/middleware"
import { searchMiddleware } from "./search/middleware"
import { handleArtworkImageDownload } from "./artwork/middleware"

export const app = express()

// Non-Reaction routes
app.get("/artwork/:artworkID/download/:filename", handleArtworkImageDownload)

app.get(
  "/*",
  searchMiddleware,
  artistMiddleware,
  async (req: Request, res, next) => {
    try {
      const pageParts = req.path.split("/")
      const pageType = pageParts[1]
      let serverApp: ServerAppResolve = {}

      /**
       * Search intentionally bypasses SSR, but we still need to inject the
       * experimental-app-shell asset into the page. Because of bundle splitting
       * we now get that back dynamically from `buildServerApp` below.
       *
       * @see https://github.com/artsy/reaction/blob/master/src/Artsy/Router/buildServerApp.tsx#L157
       */
      if (pageType === "search") {
        // Use helper defined in assetMiddleware to return fingerprinted url
        const scriptUrl = res.locals.asset("/assets/experimental-app-shell.js")
        serverApp.scripts = `<script async data-chunk="experimental-app-shell" src="${scriptUrl}"></script>`
      } else {
        serverApp = await buildServerApp({
          context: buildServerAppContext(req, res),
{'fraction_non_alphanumeric': 0.11547844944429385, 'fraction_numerical': 0.002168609379235565, 'mean_word_length': 3.823529411764706, 'pattern_counts': {'":': 0, '<': 7, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3626030', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1051, 'n_words': 259}