<commit_before>
express = require('express')
http = require('http')
winston = require('winston')
socketio = require('socket.io')
bodyParser = require('body-parser')

module.exports = class WebServer
  constructor: (@_server, @_config) ->
    app = express()

    httpServer = http.Server(app)
    io = socketio(httpServer)

    app.use bodyParser.urlencoded()
    app.use bodyParser.json()

    app.get /^\/api\/paths\/(.*)$/, (req, res) =>
      path = @normalizePath(unescape(req.params[0]))
      res.json @_server.controls.findMembersOfPath(path)

    app.get "/api/controls", (req, res) =>
      res.json @_server.controls

    app.get "/api/controls/:controlId", (req, res) =>
      control = @_server.controls.get(req.params.controlId)
      res.json control

    app.post "/api/controls/:controlId/commands/:commandId", (req, res) =>
      control = @_server.controls.get(req.params.controlId)
      control.executeCommand req.params.commandId, req.body
        .then -> res.json success: true
        .catch (why) =>
          @log 'warn', "Failed to execute command on #{req.params.controlId}: #{why}"
          res.json 500, {success: false, message: why}
        .done()

    app.use express.static(__dirname + '/public')

    io.on 'connection', (socket) =>
      @log 'debug', 'A client socket connected'
      notifyControlChange = (model) =>
        @log 'verbose', "Notifying client of change to control #{model.id}"
        socket.emit 'control:change', model.toJSON()
      @_server.controls.on 'change', notifyControlChange, socket

      socket.on 'disconnect', =>
        @log 'debug', 'Client socket disconnected; unregistering notifications'
        @_server.controls.off 'change', notifyControlChange, socket

    httpServer.listen @_config.port, =>
      @log 'info', "Listening on port #{httpServer.address().port}"<commit_msg>Show actual reason for command exec brokenness<commit_after>
express = require('express')
http = require('http')
winston = require('winston')
socketio = require('socket.io')
bodyParser = require('body-parser')

module.exports = class WebServer
  constructor: (@_server, @_config) ->
    app = express()

    httpServer = http.Server(app)
    io = socketio(httpServer)

    app.use bodyParser.urlencoded()
    app.use bodyParser.json()

    app.get /^\/api\/paths\/(.*)$/, (req, res) =>
      path = @normalizePath(unescape(req.params[0]))
      res.json @_server.controls.findMembersOfPath(path)

    app.get "/api/controls", (req, res) =>
      res.json @_server.controls

    app.get "/api/controls/:controlId", (req, res) =>
      control = @_server.controls.get(req.params.controlId)
      res.json control

    app.post "/api/controls/:controlId/commands/:commandId", (req, res) =>
      control = @_server.controls.get(req.params.controlId)
      control.executeCommand req.params.commandId, req.body
        .then -> res.json success: true
        .catch (why) =>
          @log 'warn', "Failed to execute command on #{req.params.controlId}: #{JSON.stringify(why)}"
          res.json 500, {success: false, message: why}
        .done()

    app.use express.static(__dirname + '/public')

    io.on 'connection', (socket) =>
      @log 'debug', 'A client socket connected'
      notifyControlChange = (model) =>
        @log 'verbose', "Notifying client of change to control #{model.id}"
        socket.emit 'control:change', model.toJSON()
      @_server.controls.on 'change', notifyControlChange, socket

      socket.on 'disconnect', =>
        @log 'debug', 'Client socket disconnected; unregistering notifications'
        @_server.controls.off 'change', notifyControlChange, socket

    httpServer.listen @_config.port, =>
      @log 'info', "Listening on port #{httpServer.address().port}"
{'fraction_non_alphanumeric': 0.15251530476443972, 'fraction_numerical': 0.002129358530742614, 'mean_word_length': 3.2415349887133185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '7017435', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1120, 'n_words': 267}