<commit_before>const Koa = require('koa')
const Routes = require('./routes')

module.exports = class {
  constructor(app, container, config, log) {
    this.app = app
    this.log = log
    this.container = container
    this.config = config

    this.koa = new Koa()
    container.register('koa', this.koa, { type: 'value' })

    this.port = config.get('quadro.http.port', 3000)
  }

  async initialize() {
    const koaBody = require('koa-body')
    this.koa.use(koaBody({
      multipart: true
    }))

    this.app.emit('routes-will-load', this.koa)

    let routes = await this.container.create(Routes)
    this.koa.use(await routes.build())

    this.app.emit('routes-did-load', this.koa)
  }

  async listen() {
    let port = this.port
    return new Promise((resolve) => {
      let http = this.koa.listen(port, () => {
        this.log.info({ port }, 'HTTP Server listening')
        resolve(this.configure(http))
      })
    })
  }

  configure(http) {
    let timeout = this.config.get('quadro.http.timeout')
    if (timeout) http.setTimeout(timeout)

    return http
  }
}<commit_msg>updated http_server changes to reflect code review comments<commit_after>const Koa = require('koa')
const Routes = require('./routes')

module.exports = class {
  constructor(app, container, config, log) {
    this.app = app
    this.log = log
    this.container = container
    this.config = config

    this.koa = new Koa()
    container.register('koa', this.koa, { type: 'value' })

    this.port = config.get('quadro.http.port', 3000)
  }

  async initialize() {
    const koaBody = require('koa-body')
    this.koa.use(koaBody({
      multipart: true
    }))

    await this.app.emit('routes-will-load', { quadroHttpServer: this })

    let routes = await this.container.create(Routes)
    this.koa.use(await routes.build())

    await this.app.emit('routes-did-load', { quadroHttpServer: this })
  }

  async listen() {
    let port = this.port
    return new Promise((resolve) => {
      let http = this.koa.listen(port, () => {
        this.log.info({ port }, 'HTTP Server listening')
        resolve(this.configure(http))
      })
    })
  }

  configure(http) {
    let timeout = this.config.get('quadro.http.timeout')
    if (timeout) http.setTimeout(timeout)

    return http
  }
}
{'fraction_non_alphanumeric': 0.15008726003490402, 'fraction_numerical': 0.0034904013961605585, 'mean_word_length': 2.847315436241611, 'pattern_counts': {'":': 0, '<': 3, '<?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': '781861', 'n_tokens_mistral': 772, 'n_tokens_neox': 752, 'n_words': 159}