<commit_before>// This grants us source map support, which is handy as our webpack bundling
// for the server will include source maps. Therefore we will have nice stack
// traces again for our server.
import "source-map-support/register"

import express from "express"
import compression from "compression"
import hpp from "hpp"
import helmet from "helmet"

import React from "react"
import { renderToString } from "react-dom/server"

import ClientBundleAssets from "../../build/client/assets.json"
import Button from "../components/Button"

// Create our express based server.
const app = express()

// Don't expose any software information to hackers.
app.disable("x-powered-by")

// Prevent HTTP Parameter pollution.
app.use(hpp())

// Content Security Policy
app.use(helmet.contentSecurityPolicy({
  defaultSrc: [ "'self'" ],
  scriptSrc: [ "'self'" ],
  styleSrc: [ "'self'" ],
  imgSrc: [ "'self'" ],
  connectSrc: [ "'self'", "ws:" ],
  fontSrc: [ "'self'" ],
  objectSrc: [ "'none'" ],
  mediaSrc: [ "'none'" ],
  frameSrc: [ "'none'" ],
}))

app.use(helmet.xssFilter())
app.use(helmet.frameguard("deny"))
app.use(helmet.ieNoOpen())
app.use(helmet.noSniff())

// Response compression.
app.use(compression())

// Configure static serving of our webpack bundled client files.
app.use(process.env.PUBLIC_PATH, express.static(process.env.OUTPUT_PATH))

// Test
app.get('/', function (request, response)
{
  console.log("ASSETS: ", ClientBundleAssets)
  if (true)
  {

    const html = renderToString( <Button>TestButton</Button> )
    const js = ClientBundleAssets.main.js;
    const css = ClientBundleAssets.main.css;

    var page = `
      <link rel="stylesheet" href="${css}"/>
      ${html}
      <script src="${js}"></script>
    `

    response.status(200).send(page)
  }
  else
  {
    response.status(404).send("Not found")
  }
});

// Create an http listener for our express app.
const listener = app.listen(parseInt(process.env.API_PORT, 10))

// User feedback
console.log(`Running server at port ${process.env.API_PORT}.`)<commit_msg>Made routing more dynamic<commit_after>// This grants us source map support, which is handy as our webpack bundling
// for the server will include source maps. Therefore we will have nice stack
// traces again for our server.
import "source-map-support/register"

import express from "express"
import compression from "compression"
import hpp from "hpp"
import helmet from "helmet"

import React from "react"
import { renderToString } from "react-dom/server"

import ClientBundleAssets from "../../build/client/assets.json"
import Button from "../components/Button"

// Create our express based server.
const app = express()

// Don't expose any software information to hackers.
app.disable("x-powered-by")

// Prevent HTTP Parameter pollution.
app.use(hpp())

// Content Security Policy
app.use(helmet.contentSecurityPolicy({
  defaultSrc: [ "'self'" ],
  scriptSrc: [ "'self'" ],
  styleSrc: [ "'self'" ],
  imgSrc: [ "'self'" ],
  connectSrc: [ "'self'", "ws:" ],
  fontSrc: [ "'self'" ],
  objectSrc: [ "'none'" ],
  mediaSrc: [ "'none'" ],
  frameSrc: [ "'none'" ],
}))

app.use(helmet.xssFilter())
app.use(helmet.frameguard("deny"))
app.use(helmet.ieNoOpen())
app.use(helmet.noSniff())

// Response compression.
app.use(compression())

// Configure static serving of our webpack bundled client files.
app.use(process.env.PUBLIC_PATH, express.static(process.env.OUTPUT_PATH))

// Test
app.get('/button/:label', function (request, response)
{
  console.log("ASSETS: ", ClientBundleAssets)

  if (true)
  {

    const html = renderToString( <Button>{request.params.label}</Button> )
    const js = ClientBundleAssets.main.js;
    const css = ClientBundleAssets.main.css;

    var page = `
      <link rel="stylesheet" href="${css}"/>
      ${html}
      <script src="${js}"></script>
    `

    response.status(200).send(page)
  }
  else
  {
    response.status(404).send("Not found")
  }
});

// Create an http listener for our express app.
const listener = app.listen(parseInt(process.env.API_PORT, 10))

// User feedback
console.log(`Running server at port ${process.env.API_PORT}.`)
{'fraction_non_alphanumeric': 0.1565217391304348, 'fraction_numerical': 0.003864734299516908, 'mean_word_length': 3.9891566265060243, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4776889', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1280, 'n_words': 358}