<commit_before>'use strict'

const http = require('http')
const connect = require('connect')
const path = require('path')

class Server {
  constructor (nuxt) {
    this.nuxt = nuxt
    // Initialize
    this.app = connect()
    this.server = http.createServer(this.app)
    this.nuxt.ready()
    .then(() => {
      // Add Middleware
      this.nuxt.options.serverMiddleware.forEach(m => {
        this.useMiddleware(m)
      })
      // Add default render middleware
      this.useMiddleware(this.render.bind(this))
    })
    return this
  }

  useMiddleware (m) {
    // Require if needed
    if (typeof m === 'string') {
      let src = m
      // Using ~ or ./ shorthand to resolve from project srcDir
      if (src.indexOf('~') === 0 || src.indexOf('./') === 0) {
        src = path.join(this.nuxt.options.srcDir, src.substr(1))
      }
      // eslint-disable-next-line no-eval
      m = eval('require')(src)
    }
    if (m instanceof Function) {
      this.app.use(m)
    } else if (m && m.path && m.handler) {
      this.app.use(m.path, m.handler)
    }
  }

  render (req, res, next) {
    this.nuxt.render(req, res)
    return this
  }

  listen (port, host) {
    host = host || '127.0.0.1'
    port = port || 3000
    this.nuxt.ready()
    .then(() => {
      this.server.listen(port, host, () => {
        console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console
      })
    })
    return this
  }

  close (cb) {
    return this.server.close(cb)
  }
}

export default Server<commit_msg>Display localhost instead of 0.0.0.0<commit_after>'use strict'

const http = require('http')
const connect = require('connect')
const path = require('path')

class Server {
  constructor (nuxt) {
    this.nuxt = nuxt
    // Initialize
    this.app = connect()
    this.server = http.createServer(this.app)
    this.nuxt.ready()
    .then(() => {
      // Add Middleware
      this.nuxt.options.serverMiddleware.forEach(m => {
        this.useMiddleware(m)
      })
      // Add default render middleware
      this.useMiddleware(this.render.bind(this))
    })
    return this
  }

  useMiddleware (m) {
    // Require if needed
    if (typeof m === 'string') {
      let src = m
      // Using ~ or ./ shorthand to resolve from project srcDir
      if (src.indexOf('~') === 0 || src.indexOf('./') === 0) {
        src = path.join(this.nuxt.options.srcDir, src.substr(1))
      }
      // eslint-disable-next-line no-eval
      m = eval('require')(src)
    }
    if (m instanceof Function) {
      this.app.use(m)
    } else if (m && m.path && m.handler) {
      this.app.use(m.path, m.handler)
    }
  }

  render (req, res, next) {
    this.nuxt.render(req, res)
    return this
  }

  listen (port, host) {
    host = host || 'localhost'
    port = port || 3000
    this.nuxt.ready()
    .then(() => {
      this.server.listen(port, host, () => {
        let _host = host === '0.0.0.0' ? 'localhost' : host
        console.log('Ready on http://%s:%s', _host, port) // eslint-disable-line no-console
      })
    })
    return this
  }

  close (cb) {
    return this.server.close(cb)
  }
}

export default Server
{'fraction_non_alphanumeric': 0.16316793893129772, 'fraction_numerical': 0.008905852417302799, 'mean_word_length': 2.189655172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '1916598', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1062, 'n_words': 241}