<commit_before>// these need to occur after dotenv
var express = require('express')
var bodyParser = require('body-parser')
var debug = require('debug')('pdf:api')
var error = require('./error')

function createApi(queue, options = {}) {
  var api = express()
  api.use(bodyParser.json())

  var token = options.token

  if (!token) {
    debug('Warning: The server should be protected using a token.')
  }

  api.post('/', function(req, res) {
    var authHeader = req.get('Authorization')

    if (token && (!authHeader || authHeader.replace(/Bearer (.*)$/, '$1') !== token)) {
      res.status(401).json(error.createErrorResponse(error.ERROR_INVALID_TOKEN))
      return
    }

    var response = queue.addToQueue({
      url: req.body.url,
      meta: req.body.meta || {}
    })

    if (error.isError(response)) {
      res.status(422).json(response)
      return
    }

    res.status(201).json(response)
  })

  return api
}

module.exports = createApi<commit_msg>make token regex case insensitive<commit_after>// these need to occur after dotenv
var express = require('express')
var bodyParser = require('body-parser')
var debug = require('debug')('pdf:api')
var error = require('./error')

function createApi(queue, options = {}) {
  var api = express()
  api.use(bodyParser.json())

  var token = options.token

  if (!token) {
    debug('Warning: The server should be protected using a token.')
  }

  api.post('/', function(req, res) {
    var authHeader = req.get('Authorization')

    if (token && (!authHeader || authHeader.replace(/Bearer (.*)$/i, '$1') !== token)) {
      res.status(401).json(error.createErrorResponse(error.ERROR_INVALID_TOKEN))
      return
    }

    var response = queue.addToQueue({
      url: req.body.url,
      meta: req.body.meta || {}
    })

    if (error.isError(response)) {
      res.status(422).json(response)
      return
    }

    res.status(201).json(response)
  })

  return api
}

module.exports = createApi
{'fraction_non_alphanumeric': 0.1599592460519613, 'fraction_numerical': 0.010188487009679063, 'mean_word_length': 3.297592997811816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3037777', 'n_tokens_mistral': 634, 'n_tokens_neox': 608, 'n_words': 144}