<commit_before>/*global require,process,__dirname,console*/
(function () {
    "use strict";
    var express = require('express'),
        morgan = require('morgan'),
        bodyParser = require('body-parser'),
        methodOverride = require('method-override'),
        cookieParser = require('cookie-parser'),
        express_layout = require('express3-ejs-layout'),
        compression = require('compression'),
        http = require('http'),
        path = require('path'),
        app = express(),
        route = require("./route"),
        config = require("./config.js"),
        app_package = require("./package.json"),
        core = require("./core/"),
        locals_app = {
            title: "AngularJS Nice Things",
            version: app_package.version,
            env: config.env
        };
    app.use(compression());
    app.use(bodyParser());
    app.use(methodOverride());
    app.use(cookieParser(config.cookie_secret));
    app.set('views', __dirname + '/web/view');
    app.use(express.static(__dirname + '/web/static'));// {maxAge: 31557600000}
    app.set('view engine', 'html');
    app.engine('html', require('ejs').renderFile);
    app.use(express_layout);
    app.set('layout', 'layout');
    app.disable("x-powered-by");

    morgan.token('data', function (req) {
        return "params:" + JSON.stringify(req.params) + ",query:" + JSON.stringify(req.query) + ",body:" + JSON.stringify(req.body);
    });
    morgan.token('date', function () {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
    });
    if ('development' === config.env) {
        app.use(morgan(':method :url :status :remote-addr :data [:date][:response-time ms]'));
    } else {
        app.use(morgan(':method :url :status :remote-addr [:date][:response-time ms]'));
    }
    // development only
    if ('development' === config.env) {
        locals_app.site_scripts = config.site_scripts;
    }
    app.locals.app = locals_app;

    //初始化路由
    route(app);

    //create server
    app.listen(config.port, function () {
        console.log('ng-nice server listening on port ' + config.port + " in env " + config.env);
    });

    if (config.env === 'production') {
        process.on("uncaughtException", function (err) {
            console.log("process uncaughtException:" + err);
        });
    }
})();

<commit_msg>URL检查并重定向<commit_after>/*global require,process,__dirname,console*/
(function () {
    "use strict";
    var express = require('express'),
        morgan = require('morgan'),
        bodyParser = require('body-parser'),
        methodOverride = require('method-override'),
        cookieParser = require('cookie-parser'),
        express_layout = require('express3-ejs-layout'),
        compression = require('compression'),
        http = require('http'),
        path = require('path'),
        app = express(),
        route = require("./route"),
        config = require("./config.js"),
        app_package = require("./package.json"),
        core = require("./core/"),
        locals_app = {
            title  : "AngularJS Nice Things",
            version: app_package.version,
            env    : config.env
        };
    app.use(compression());
    app.use(bodyParser());
    app.use(methodOverride());
    app.use(cookieParser(config.cookie_secret));
    app.set('views', __dirname + '/web/view');
    app.use(express.static(__dirname + '/web/static'));// {maxAge: 31557600000}
    app.set('view engine', 'html');
    app.engine('html', require('ejs').renderFile);
    app.use(express_layout);
    app.set('layout', 'layout');
    app.disable("x-powered-by");

    morgan.token('data', function (req) {
        return "params:" + JSON.stringify(req.params) + ",query:" + JSON.stringify(req.query) + ",body:" + JSON.stringify(req.body);
    });
    morgan.token('date', function () {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
    });
    if ('development' === config.env) {
        app.use(morgan(':method :url :status :remote-addr :data [:date][:response-time ms]'));
        locals_app.site_scripts = config.site_scripts;
    } else {
        app.use(morgan(':method :url :status :remote-addr [:date][:response-time ms]'));
        //URL 检查并重定向
        app.use(function (req, res, next) {
            if (req.headers.host == "angular.duapp.com") {
                res.writeHead(301, {'Location': 'http://' + config.host + req.url});
                res.end();
                return;
            }
            if (req.headers.host !== config.host) {
                return res.redirect('http://' + config.host + req.url);
            }
            else {
                next();
            }
        });
    }

    app.locals.app = locals_app;

    //初始化路由
    route(app);

    //create server
    app.listen(config.port, function () {
        console.log('ng-nice server listening on port ' + config.port + " in env " + config.env);
    });

    if (config.env === 'production') {
        process.on("uncaughtException", function (err) {
            console.log("process uncaughtException:" + err);
        });
    }
})();


{'fraction_non_alphanumeric': 0.18477043673012317, 'fraction_numerical': 0.005412467338559164, 'mean_word_length': 2.4485199485199485, 'pattern_counts': {'":': 4, '<': 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': '1935397', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1613, 'n_words': 294}