<commit_before>/**
 * Copyright 2014, Yahoo! Inc.
 * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
/**
 * list of registered fetchers
 */
var fetchersList = {},
    OP_READ = 'read',
    OP_CREATE = 'create',
    OP_UPDATE = 'update',
    GET = 'GET',
    qs = require('querystring'),
    debug = require('debug')('Fetchr:fetchr'),
    defaultPathPrefix = '/api',
    pathPrefix = '';

var Fetcher = {
    /**
     * @method middleware
     * @param {Object} config Configuration object for middleware
     * @returns {Function} middleware
     *     @param {Object} req
     *     @param {Object} res
     *     @param {Object} next
     */
    middleware: function (config) {
        pathPrefix = config.pathPrefix || defaultPathPrefix;
        return function (req, res, next) {
            var request;

            if (req.path.indexOf(pathPrefix) !== 0) {
                //Skip non fetchr requests
                next();
                return;
            }

            if (req.method === GET) {
                var defaultPath = pathPrefix + '/resource/',
                    path = req.path.substr(defaultPath.length).split(';');
                request = {
                    resource: path.shift(),
                    operation: OP_READ,
                    params: qs.parse(path.join('&')),
                    context: {},
                    callback: function (err, data) {
                        if (err) {
                            res.send('400', 'request failed');
                        }
                        res.json(data);
                    }
                };
            } else {
                var requests = req.body.requests,
                    context = req.body.context;<commit_msg>be defensive about middleware config<commit_after>/**
 * Copyright 2014, Yahoo! Inc.
 * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
/**
 * list of registered fetchers
 */
var fetchersList = {},
    OP_READ = 'read',
    OP_CREATE = 'create',
    OP_UPDATE = 'update',
    GET = 'GET',
    qs = require('querystring'),
    debug = require('debug')('Fetchr:fetchr'),
    defaultPathPrefix = '/api',
    pathPrefix = '';

var Fetcher = {
    /**
     * @method middleware
     * @param {Object} config Configuration object for middleware
     * @returns {Function} middleware
     *     @param {Object} req
     *     @param {Object} res
     *     @param {Object} next
     */
    middleware: function (config) {
        config = config || {};
        pathPrefix = config.pathPrefix || defaultPathPrefix;
        return function (req, res, next) {
            var request;

            if (req.path.indexOf(pathPrefix) !== 0) {
                //Skip non fetchr requests
                next();
                return;
            }

            if (req.method === GET) {
                var defaultPath = pathPrefix + '/resource/',
                    path = req.path.substr(defaultPath.length).split(';');
                request = {
                    resource: path.shift(),
                    operation: OP_READ,
                    params: qs.parse(path.join('&')),
                    context: {},
                    callback: function (err, data) {
                        if (err) {
                            res.send('400', 'request failed');
                        }
                        res.json(data);
                    }
                };
            } else {
                var requests = req.body.requests,
                    context = req.body.context;
{'fraction_non_alphanumeric': 0.12015503875968993, 'fraction_numerical': 0.004429678848283499, 'mean_word_length': 1.4054593874833554, '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': '6294363', 'n_tokens_mistral': 955, 'n_tokens_neox': 893, 'n_words': 241}