<commit_before>'use strict'

const reponseHeadersJson = {
  'Access-Control-Allow-Origin': '*', // Required for CORS support to work
  'Access-Control-Allow-Credentials': true,
  'Access-Control-Expose-Headers': 'link',
  'Content-Type': "'application/json'"
}

module.exports.router = (event, context, callback) => {
  const routes = {
    '/example/message': exampleMessageGet,
    '/example/do-something': exampleDoSomethingPost
  }
  let handler = routes[event.path]
  const response = handler(event, context, callback)
  callback(null, response)
}

function exampleMessageGet (event, context, callback) {
  let headers = reponseHeadersJson
  let scheme = event.headers['X-Forwarded-Proto']
  let host = event.headers.Host
  let path = event.requestContext.path.replace('example/message','example/do-something')
  headers.link = `<${scheme}://${host}${path}>; rel="related"`
  return {
    statusCode: 200,
    headers: headers,
    body: JSON.stringify({
      message: 'Hello, World!',
    })
  }
}

function exampleDoSomethingPost (event, context, callback) {
  let body = JSON.parse(event.body)
  if (body.constructor !== Array) {
    return {
      statusCode: 400,
      headers: reponseHeadersJson,
      body: JSON.stringify({
        message: 'The supplied request body must be a JSON array',
        statusCode: '400'
      })
    }
  }
  let itemCount = body.length
  return {
    statusCode: 200,
    headers: reponseHeadersJson,
    body: JSON.stringify({
      result: 'Thanks for sending that data',
      submittedItems: itemCount
    })
  }<commit_msg>Fix var name typo (#141)<commit_after>'use strict'

const responseHeadersJson = {
  'Access-Control-Allow-Origin': '*', // Required for CORS support to work
  'Access-Control-Allow-Credentials': true,
  'Access-Control-Expose-Headers': 'link',
  'Content-Type': "'application/json'"
}

module.exports.router = (event, context, callback) => {
  const routes = {
    '/example/message': exampleMessageGet,
    '/example/do-something': exampleDoSomethingPost
  }
  let handler = routes[event.path]
  const response = handler(event, context, callback)
  callback(null, response)
}

function exampleMessageGet (event, context, callback) {
  let headers = responseHeadersJson
  let scheme = event.headers['X-Forwarded-Proto']
  let host = event.headers.Host
  let path = event.requestContext.path.replace('example/message','example/do-something')
  headers.link = `<${scheme}://${host}${path}>; rel="related"`
  return {
    statusCode: 200,
    headers: headers,
    body: JSON.stringify({
      message: 'Hello, World!',
    })
  }
}

function exampleDoSomethingPost (event, context, callback) {
  let body = JSON.parse(event.body)
  if (body.constructor !== Array) {
    return {
      statusCode: 400,
      headers: responseHeadersJson,
      body: JSON.stringify({
        message: 'The supplied request body must be a JSON array',
        statusCode: '400'
      })
    }
  }
  let itemCount = body.length
  return {
    statusCode: 200,
    headers: responseHeadersJson,
    body: JSON.stringify({
      result: 'Thanks for sending that data',
      submittedItems: itemCount
    })
  }
{'fraction_non_alphanumeric': 0.13445112306232204, 'fraction_numerical': 0.008541600759253401, 'mean_word_length': 3.5365853658536586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6915202', 'n_tokens_mistral': 963, 'n_tokens_neox': 937, 'n_words': 234}