<commit_before>/**
 * light-server
 *
 * Serve, watch, exucute commands and live-reload, all in one.
 *
 * Copyright (c) 2017 by <NAME>
 */
'use strict'

var connect = require('connect')
var morgan = require('morgan')
var serveStatic = require('serve-static')
var injector = require('connect-injector')
var Watcher = require('./watcher')
var LR = require('./livereload')
var spawn = require('child_process').spawn
var os = require('os').type()

function LightServer (options) {
  if (!(this instanceof LightServer)) return new LightServer(options)
  this.options = options
  if (os === 'Windows_NT') {
    this.shell = 'cmd'
    this.firstParam = '/c'
  } else {
    this.shell = 'bash'
    this.firstParam = '-c'
  }
}

LightServer.prototype.writeLog = function (logLine) {
  !this.options.quiet && console.log(logLine)
}

LightServer.prototype.start = function () {
  var _this = this
  if (!_this.options.serve && !_this.options.proxy) {
    _this.watch()
    return
  }

  var app = connect()
  !this.options.quiet && app.use(morgan('dev'))

  _this.lr = LR({
    quiet: _this.options.quiet,
    http2: _this.options.http2
  })
  app.use(_this.lr.middleFunc)
  app.use(injector(
    function (req, res) {
      return res.getHeader('content-type') && res.getHeader('content-type').indexOf('text/html') !== -1
    },

    function (data, req, res, callback) {
      callback(null, data.toString().replace('</body>', '<script src="/__lightserver__/reload-client.js"></script></body>'))
    })
  )

  if (_this.options.serve) {
    app.use(serveStatic(_this.options.serve))
  }

  if (_this.options.proxy) {
    var proxy = require('./proxy')
    app.use(proxy(_this.options.proxy, _this.options.proxypath).middleFunc)<commit_msg>Add a default extension to static files (#33)<commit_after>/**
 * light-server
 *
 * Serve, watch, exucute commands and live-reload, all in one.
 *
 * Copyright (c) 2017 by <NAME>
 */
'use strict'

var connect = require('connect')
var morgan = require('morgan')
var serveStatic = require('serve-static')
var injector = require('connect-injector')
var Watcher = require('./watcher')
var LR = require('./livereload')
var spawn = require('child_process').spawn
var os = require('os').type()

function LightServer (options) {
  if (!(this instanceof LightServer)) return new LightServer(options)
  this.options = options
  if (os === 'Windows_NT') {
    this.shell = 'cmd'
    this.firstParam = '/c'
  } else {
    this.shell = 'bash'
    this.firstParam = '-c'
  }
}

LightServer.prototype.writeLog = function (logLine) {
  !this.options.quiet && console.log(logLine)
}

LightServer.prototype.start = function () {
  var _this = this
  if (!_this.options.serve && !_this.options.proxy) {
    _this.watch()
    return
  }

  var app = connect()
  !this.options.quiet && app.use(morgan('dev'))

  _this.lr = LR({
    quiet: _this.options.quiet,
    http2: _this.options.http2
  })
  app.use(_this.lr.middleFunc)
  app.use(injector(
    function (req, res) {
      return res.getHeader('content-type') && res.getHeader('content-type').indexOf('text/html') !== -1
    },

    function (data, req, res, callback) {
      callback(null, data.toString().replace('</body>', '<script src="/__lightserver__/reload-client.js"></script></body>'))
    })
  )

  if (_this.options.serve) {
    app.use(serveStatic(_this.options.serve, { extensions: ['html'] }))
  }

  if (_this.options.proxy) {
    var proxy = require('./proxy')
    app.use(proxy(_this.options.proxy, _this.options.proxypath).middleFunc)
{'fraction_non_alphanumeric': 0.171875, 'fraction_numerical': 0.004545454545454545, 'mean_word_length': 3.669761273209549, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '28428', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1159, 'n_words': 248}