<commit_before>const express = require('express')
const bodyParser = require('body-parser')
const log = require('winston')
const config = require('../config')
const allowCors = require('./allowCors')
const fileServer = require('./fileServer')

const app = express()

app.use(bodyParser.json())
app.use(allowCors)
app.use('/donation', require('./routes/donation'))
app.use('/', fileServer)

const listen = () => {
  return new Promise((resolve) => {
    const server = app.listen(config.http.port, () => {
      const addr = server.address()
      resolve(`Server running on: http://${addr.address}:${addr.port}`)
    })
  })
}

// eslint-disable-next-line
app.use((err, req, res, next) => {
  const status = err.status || 500
  res.status(status)

  if(status === 500) {
    log.error(err.message || 'Server error')
    return res.end()
  }

  res.json({message: err.message})
})

module.exports = {
  listen
}<commit_msg>Log stack trace if server error<commit_after>const express = require('express')
const bodyParser = require('body-parser')
const log = require('winston')
const config = require('../config')
const allowCors = require('./allowCors')
const fileServer = require('./fileServer')

const app = express()

app.use(bodyParser.json())
app.use(allowCors)
app.use('/donation', require('./routes/donation'))
app.use('/', fileServer)

const listen = () => {
  return new Promise((resolve) => {
    const server = app.listen(config.http.port, () => {
      const addr = server.address()
      resolve(`Server running on: http://${addr.address}:${addr.port}`)
    })
  })
}

// eslint-disable-next-line
app.use((err, req, res, next) => {
  const status = err.status || 500
  res.status(status)

  if(status === 500) {
    log.error(err.message || 'Server error')
    log.error(err.stack)
    return res.end()
  }

  res.json({message: err.message})
})

module.exports = {
  listen
}
{'fraction_non_alphanumeric': 0.1886592474827769, 'fraction_numerical': 0.006359300476947536, 'mean_word_length': 3.8785529715762275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3172360', 'n_tokens_mistral': 622, 'n_tokens_neox': 604, 'n_words': 132}