<commit_before>var express = require('express'),
    fs = require('fs'),
    ejs = require('ejs'),
    url = require('url'),
    http = require('http'),
    compress = require('compression'),
    bodyParser = require('body-parser'),
    logfmt = require("logfmt"),
    app = new express(),
    server = http.createServer(app),
    io = require('socket.io').listen(server),
    jsondiffpatch = require('jsondiffpatch').create({
        textDiff: {
            minLength: 60
        }
    });

var session = {};

/**
 *  uitl functions
 **/
function readFile (path) {
    if (fs.existsSync(path)) {
        return fs.readFileSync(path, 'utf-8');
    } else {
        return '';
    }
}

/**
 *  initialize
 **/
/* =================================================================== */
if (!fs.existsSync('/tmp')) {
    fs.mkdirSync('/tmp');
}
/* =================================================================== */

app.use(logfmt.requestLogger());
app.use(compress());
app.use(express.static(__dirname + '/public'));
app.use(bodyParser());


/* =================================================================== */
/**
 *  Middlewares
 **/

/**
 *  Get inpsector form url
 **/
function inspectorIdParse (req, res, next) {
    var search = url.parse(req.url).search;
    search && (req.inspectorId = search.replace(/^\?/, '').split('&')[0]);
    next();
}
/**
 *  Post body parse
 **/
function rawBody(req, res, next) {
  req.setEncoding('utf8');
  req.rawBody = '';
  req.on('data', function(chunk) {
    req.rawBody += chunk;
  });
  req.on('end', function(){
    next();
  });
}


/* =================================================================== */
/**
 *  Client routes
 **/
app.get('/inspector', inspectorIdParse, function (req, res) {
    var script = readFile('./public/client/script.js', 'utf-8'),
        jsonify = readFile('./public/client/jsonify.js', 'utf-8');
        consoleJS = readFile('./public/client/console.js', 'utf-8');
    res.setHeader('Content-Type', 'application/javascript');
    res.setHeader('Access-Control-Allow-Origin', 'http://' + req.headers.host);
    res.send(ejs.render(script, {
        host: 'http://' + req.headers.host,
        inspectorId: req.inspectorId,
        jsonify: jsonify,
        console: consoleJS
    }));
});<commit_msg>CORS for all request<commit_after>var express = require('express'),
    fs = require('fs'),
    ejs = require('ejs'),
    url = require('url'),
    http = require('http'),
    compress = require('compression'),
    bodyParser = require('body-parser'),
    logfmt = require("logfmt"),
    app = new express(),
    server = http.createServer(app),
    io = require('socket.io').listen(server),
    jsondiffpatch = require('jsondiffpatch').create({
        textDiff: {
            minLength: 60
        }
    });

var session = {};

/**
 *  uitl functions
 **/
function readFile (path) {
    if (fs.existsSync(path)) {
        return fs.readFileSync(path, 'utf-8');
    } else {
        return '';
    }
}

/**
 *  initialize
 **/
/* =================================================================== */
if (!fs.existsSync('/tmp')) {
    fs.mkdirSync('/tmp');
}
/* =================================================================== */
app.use(logfmt.requestLogger());
app.use(compress());
/**
 *  Global CORS
 **/
app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', 'http://' + req.headers.host);
    res.setHeader('Access-Control-Allow-Methods', 'PUT,POST,HEAD,GET,OPTIONS,PATCH');
    next();
})
app.use(express.static(__dirname + '/public'));
app.use(bodyParser());


/* =================================================================== */
/**
 *  Middlewares
 **/

/**
 *  Get inpsector form url
 **/
function inspectorIdParse (req, res, next) {
    var search = url.parse(req.url).search;
    search && (req.inspectorId = search.replace(/^\?/, '').split('&')[0]);
    next();
}
/**
 *  Post body parse
 **/
function rawBody(req, res, next) {
  req.setEncoding('utf8');
  req.rawBody = '';
  req.on('data', function(chunk) {
    req.rawBody += chunk;
  });
  req.on('end', function(){
    next();
  });
}

/* =================================================================== */
/**
 *  Client routes
 **/
app.get('/inspector', inspectorIdParse, function (req, res) {
    var script = readFile('./public/client/script.js', 'utf-8'),
        jsonify = readFile('./public/client/jsonify.js', 'utf-8');
        consoleJS = readFile('./public/client/console.js', 'utf-8');
    res.setHeader('Content-Type', 'application/javascript');
    res.setHeader('Access-Control-Allow-Origin', 'http://' + req.headers.host);
    res.send(ejs.render(script, {
        host: 'http://' + req.headers.host,
        inspectorId: req.inspectorId,
        jsonify: jsonify,
        console: consoleJS
    }));
});
{'fraction_non_alphanumeric': 0.29794307084978183, 'fraction_numerical': 0.0033243299397465197, 'mean_word_length': 3.40036563071298, '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': '5138752', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1442, 'n_words': 251}