<commit_before>appManager = require '../lib/app_manager'
{getProxy} = require '../lib/proxy'
send = require 'send'
lockedpath = require 'lockedpath'
logger = require('printit')
    date: false
    prefix: 'controllers:applications'

# get path to start a static app
getPathForStaticApp = (appName, path, root, callback) ->
    logger.info "Starting static app #{appName}"
    path += 'index.html' if path is '/' or path is '/public/'
    callback lockedpath(root).join path

forwardRequest = (req, res, errTemplate, next) ->
    connectionClosed = false
    req.on 'close', -> connectionClosed = true
    res.on 'close', -> connectionClosed = true
    appName = req.params.name
    shouldStart = -1 is req.url.indexOf 'socket.io'
    appManager.ensureStarted appName, shouldStart, (err, result) ->
        if connectionClosed
            return
        else if err?
            error = new Error err.msg
            error.status = err.code
            error.template = errTemplate err
            next error
        else if result.type is 'static'<commit_msg>Improve the fix for sockets in CLOSE_WAIT<commit_after>appManager = require '../lib/app_manager'
{getProxy} = require '../lib/proxy'
send = require 'send'
lockedpath = require 'lockedpath'
logger = require('printit')
    date: false
    prefix: 'controllers:applications'

# get path to start a static app
getPathForStaticApp = (appName, path, root, callback) ->
    logger.info "Starting static app #{appName}"
    path += 'index.html' if path is '/' or path is '/public/'
    callback lockedpath(root).join path

forwardRequest = (req, res, errTemplate, next) ->
    appName = req.params.name
    shouldStart = -1 is req.url.indexOf 'socket.io'
    appManager.ensureStarted appName, shouldStart, (err, result) ->
        if not res.connection or res.connection.destroyed
            return
        else if err?
            error = new Error err.msg
            error.status = err.code
            error.template = errTemplate err
            next error
        else if result.type is 'static'
{'fraction_non_alphanumeric': 0.10813443740867024, 'fraction_numerical': 0.000974184120798831, 'mean_word_length': 2.775735294117647, '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': '1772503', 'n_tokens_mistral': 585, 'n_tokens_neox': 576, 'n_words': 190}