<commit_before>import { buildServerApp } from 'reaction/Router'
import { Meta, query } from './components/Meta'
import { renderLayout } from '@artsy/stitch'
import { routes } from 'reaction/Apps/Artist/routes'
import express from 'express'
import metaphysics from 'lib/metaphysics.coffee'
import React from 'react'
import styled from 'styled-components'

const app = (module.exports = express())

app.get('/artist2/:artistID*', async (req, res, next) => {
  try {
    const user = req.user && req.user.toJSON()

    const { ServerApp, redirect, status } = await buildServerApp({
      initialBreakpoint: res.locals.sd.IS_MOBILE ? 'xs' : false,
      routes,
      url: req.url,
      user,
    })

    if (redirect) {
      res.redirect(302, redirect.url)
      return
    }

    // FIXME: Move this to Reaction
    const Container = styled.div`
      width: 100%;
      max-width: 1192px;
      margin: auto;
    `

    const send = {
      method: 'post',
      query,
      variables: { artistID: req.params.artistID },
    }

    const { artist } = await metaphysics(send).then(data => data)

    const isExternalReferer =
      res.locals.sd.REFERRER &&
      !res.locals.sd.REFERRER.includes(res.locals.sd.APP_URL)

    // Since this page is admin-only now, need to swap this in to test.
    // res.locals.sd.ARTIST_PAGE_CTA_ENABLED = true
    res.locals.sd.ARTIST_PAGE_CTA_ENABLED = !user && isExternalReferer
    res.locals.sd.ARTIST_PAGE_CTA_ARTIST_ID = req.params.artistID

    // Render layout
    const layout = await renderLayout({
      basePath: __dirname,
      layout: '../../components/main_layout/templates/react_redesign.jade',
      config: {
        styledComponents: true,
      },
      blocks: {
        head: () => <Meta sd={res.locals.sd} artist={artist} />,
        body: () => (
          <Container>
            <ServerApp />
          </Container>
        ),
      },
      locals: {
        ...res.locals,
        assetPackage: 'artist2',
      },
    })

    res.status(status).send(layout)
  } catch (error) {
    console.log(error)
    next(error)
  }<commit_msg>Specify PAGE_TYPE (for Volley) for new artist page<commit_after>import { buildServerApp } from 'reaction/Router'
import { Meta, query } from './components/Meta'
import { renderLayout } from '@artsy/stitch'
import { routes } from 'reaction/Apps/Artist/routes'
import express from 'express'
import metaphysics from 'lib/metaphysics.coffee'
import React from 'react'
import styled from 'styled-components'

const app = (module.exports = express())

app.get('/artist2/:artistID*', async (req, res, next) => {
  try {
    const user = req.user && req.user.toJSON()

    const { ServerApp, redirect, status } = await buildServerApp({
      initialBreakpoint: res.locals.sd.IS_MOBILE ? 'xs' : false,
      routes,
      url: req.url,
      user,
    })

    if (redirect) {
      res.redirect(302, redirect.url)
      return
    }

    // FIXME: Move this to Reaction
    const Container = styled.div`
      width: 100%;
      max-width: 1192px;
      margin: auto;
    `

    const send = {
      method: 'post',
      query,
      variables: { artistID: req.params.artistID },
    }

    const { artist } = await metaphysics(send).then(data => data)

    const isExternalReferer =
      res.locals.sd.REFERRER &&
      !res.locals.sd.REFERRER.includes(res.locals.sd.APP_URL)

    res.locals.sd.ARTIST_PAGE_CTA_ENABLED = !user && isExternalReferer
    res.locals.sd.ARTIST_PAGE_CTA_ARTIST_ID = req.params.artistID

    // While we are rolling out the new page, override the default (`artist`)
    // type inferred from the URL, for tracking and comparison purposes.
    res.locals.sd.PAGE_TYPE = 'new-artist'

    // Render layout
    const layout = await renderLayout({
      basePath: __dirname,
      layout: '../../components/main_layout/templates/react_redesign.jade',
      config: {
        styledComponents: true,
      },
      blocks: {
        head: () => <Meta sd={res.locals.sd} artist={artist} />,
        body: () => (
          <Container>
            <ServerApp />
          </Container>
        ),
      },
      locals: {
        ...res.locals,
        assetPackage: 'artist2',
      },
    })

    res.status(status).send(layout)
  } catch (error) {
    console.log(error)
    next(error)
  }
{'fraction_non_alphanumeric': 0.13173791821561337, 'fraction_numerical': 0.0055762081784386614, 'mean_word_length': 2.471774193548387, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '6796143', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1392, 'n_words': 312}