<commit_before>#!/usr/bin/env node

/*jshint node:true */

"use strict";

var express    = require('express'),
    middleware = require('./lib/middleware'),
    stats      = require('./lib/stats');

// -- Configure Express --------------------------------------------------------
var app       = express(),
    publicDir = __dirname + '/public';

app.disable('x-powered-by');

if (app.get('env') === 'development') {
    app.use(express.responseTime());
    app.use(express.logger('tiny'));
}

app.use(express.static(publicDir));
app.use(middleware.blacklist);

// Global middleware to set some security-related headers.
app.use(function (req, res, next) {
    res.set({
        'Access-Control-Allow-Origin': '*',
        'X-Content-Type-Options'     : 'nosniff'
    });

    next();
});

app.use(app.router);

// -- Routes -------------------------------------------------------------------

// Don't allow requests for Google Webmaster Central verification files, because
// rawgithub.com isn't a hosting provider and people can't own URLs under its
// domain.
app.get('*/google[0-9a-f]{16}.html',
    middleware.error403);

// Public or private gist.
app.get(/^\/[0-9A-Za-z-]+\/[0-9a-f]+\/raw\//,
    middleware.stats,
    middleware.noRobots,
    middleware.imageRedirect('https://gist.github.com'),
    middleware.proxyPath('https://gist.github.com'));

// Repo file.
app.get('/:user/:repo/:branch/*',
    middleware.stats,
    middleware.noRobots,
    middleware.imageRedirect('https://raw.github.com'),
    middleware.proxyPath('https://raw.github.com'));

// Stats API.
app.get('/api/stats', function (req, res, next) {
    var count = Math.max(0, Math.min(100, req.query.count || 100));

    res.jsonp({
        status: 'success',

        data: {
            since    : stats.since(),
            files    : stats.files().slice(0, count),
            referrers: stats.referrers().slice(0, count)
        }
    });
});

// -- Error handlers -----------------------------------------------------------
app.use(function (req, res, next) {
    res.status(404);

    if (req.accepts('html')) {
        res.sendfile(publicDir + '/errors/404.html');<commit_msg>Don't cache API responses.<commit_after>#!/usr/bin/env node

/*jshint node:true */

"use strict";

var express    = require('express'),
    middleware = require('./lib/middleware'),
    stats      = require('./lib/stats');

// -- Configure Express --------------------------------------------------------
var app       = express(),
    publicDir = __dirname + '/public';

app.disable('x-powered-by');

if (app.get('env') === 'development') {
    app.use(express.responseTime());
    app.use(express.logger('tiny'));
}

app.use(express.static(publicDir));
app.use(middleware.blacklist);

// Global middleware to set some security-related headers.
app.use(function (req, res, next) {
    res.set({
        'Access-Control-Allow-Origin': '*',
        'X-Content-Type-Options'     : 'nosniff'
    });

    next();
});

app.use(app.router);

// -- Routes -------------------------------------------------------------------

// Don't allow requests for Google Webmaster Central verification files, because
// rawgithub.com isn't a hosting provider and people can't own URLs under its
// domain.
app.get('*/google[0-9a-f]{16}.html',
    middleware.error403);

// Public or private gist.
app.get(/^\/[0-9A-Za-z-]+\/[0-9a-f]+\/raw\//,
    middleware.stats,
    middleware.noRobots,
    middleware.imageRedirect('https://gist.github.com'),
    middleware.proxyPath('https://gist.github.com'));

// Repo file.
app.get('/:user/:repo/:branch/*',
    middleware.stats,
    middleware.noRobots,
    middleware.imageRedirect('https://raw.github.com'),
    middleware.proxyPath('https://raw.github.com'));

// Stats API.
app.get('/api/stats', function (req, res, next) {
    var count = Math.max(0, Math.min(100, req.query.count || 100));

    res.set('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');

    res.jsonp({
        status: 'success',

        data: {
            since    : stats.since(),
            files    : stats.files().slice(0, count),
            referrers: stats.referrers().slice(0, count)
        }
    });
});

// -- Error handlers -----------------------------------------------------------
app.use(function (req, res, next) {
    res.status(404);

    if (req.accepts('html')) {
        res.sendfile(publicDir + '/errors/404.html');
{'fraction_non_alphanumeric': 0.25919242048274305, 'fraction_numerical': 0.011955786149334537, 'mean_word_length': 2.1093969144460027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, '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': '5634998', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1360, 'n_words': 256}