<commit_before>var URL = require('url'),
    express = require('express'),
    request = require('request');

module.exports = function createLiveStyleApp(options) {
    var app = express.createServer(),
        proxyUrl = options.proxy && URL.parse(options.proxy);

    app.configure(function () {
        app
            .use(express.logger())
            .use(require('./middleware/injectLiveStyleScriptIncludeIntoHtml')());

        if (options.mappings) {
            app
                .use(function (req, res, next) {
                    Object.keys(options.mappings).forEach(function (url) {
                        if (req.url.indexOf(url) === 0) {
                            req.url = req.url.replace(url, options.mappings[url]);
                        }
                    });
                    next();
                });
        }

        if (options.documentRoot) {
            var staticProvider = express['static'](options.documentRoot);
            app.use(function (req, res, next) {
                if (!proxyUrl || req.accepts('css') || req.accepts('text/x-less')) {
                    staticProvider(req, res, next);
                } else {
                    next();
                }
            });
        }

        if (proxyUrl) {
            app.use(function (req, res, next) {
                req.pipe(request({
                    method: req.method,
                    url: proxyUrl.protocol + '//' + proxyUrl.host + req.url,
                    onResponse: true
                }, function (err, response) {
                    if (err) {
                        res.writeHead(502, {});
                        res.end('Error connecting to upstream server: ' + err.stack);
                    } else {
                        res.writeHead(response.statusCode, response.headers);
                        response.pipe(res);
                    }
                }));
            });
        }

        app.use(express.errorHandler({dumpExceptions: true, showStack: true}));

        require('../lib/installLiveCssFileWatcherInServer')(app, {
            documentRoot: options.documentRoot,
            mappings: options.mappings
        }, require('socket.io'));
    });

    return app;
};<commit_msg>Only watch files if a documentRoot is specified.<commit_after>var URL = require('url'),
    express = require('express'),
    request = require('request');

module.exports = function createLiveStyleApp(options) {
    var app = express.createServer(),
        proxyUrl = options.proxy && URL.parse(options.proxy);

    app.configure(function () {
        app
            .use(express.logger())
            .use(require('./middleware/injectLiveStyleScriptIncludeIntoHtml')());

        if (options.mappings) {
            app
                .use(function (req, res, next) {
                    Object.keys(options.mappings).forEach(function (url) {
                        if (req.url.indexOf(url) === 0) {
                            req.url = req.url.replace(url, options.mappings[url]);
                        }
                    });
                    next();
                });
        }

        if (options.documentRoot) {
            var staticProvider = express['static'](options.documentRoot);
            app.use(function (req, res, next) {
                if (!proxyUrl || req.accepts('css') || req.accepts('text/x-less')) {
                    staticProvider(req, res, next);
                } else {
                    next();
                }
            });
        }

        if (proxyUrl) {
            app.use(function (req, res, next) {
                req.pipe(request({
                    method: req.method,
                    url: proxyUrl.protocol + '//' + proxyUrl.host + req.url,
                    onResponse: true
                }, function (err, response) {
                    if (err) {
                        res.writeHead(502, {});
                        res.end('Error connecting to upstream server: ' + err.stack);
                    } else {
                        res.writeHead(response.statusCode, response.headers);
                        response.pipe(res);
                    }
                }));
            });
        }

        app.use(express.errorHandler({dumpExceptions: true, showStack: true}));

        if (options.documentRoot) {
            require('../lib/installLiveCssFileWatcherInServer')(app, {
                documentRoot: options.documentRoot,
                mappings: options.mappings
            }, require('socket.io'));
        }
    });

    return app;
};
{'fraction_non_alphanumeric': 0.12818835840418574, 'fraction_numerical': 0.0017440592980161324, 'mean_word_length': 1.3265720081135903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2195400', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1113, 'n_words': 203}