<commit_before>/**
 * Dolman API Endpoint
 * ====================
 *
 * Exposing the library's utilities.
 */
var responses = require('./src/responses.js'),
    middlewares = require('./src/middlewares.js'),
    Typology = require('typology'),
    util = require('util');

module.exports = function(express, opts) {
  opts = opts || {};

  // Applying responses to express
  responses(express);

  // Building internal typology
  var types;

  if (opts.typology instanceof Typology)
    types = opts.typology;
  else
    types = new Typology(opts.typology || {});

  // Internal RAM cache
  var ramCache = {};

  // Building the router function
  function makeRouter(routes, o) {
    o = o || {};

    var router = express.Router(),
        after = [].concat(o.after || []);

    routes.forEach(function(route) {
      if (!route.url)
        throw Error('dolman.router: one route has no url: ' + util.inspect(route));

      if (!route.action)
        throw Error('dolman.router: the route for url ' + route.url + ' has no action.');

      // Applying before middlewares
      var routeMiddlewares = [];

      // Validation
      if (route.validate)
        routeMiddlewares.push(middlewares.validate(types, route.validate));

      // Cache
      if (route.ramCache)
        routeMiddlewares.push(middlewares.ramCache(ramCache, route.ramCache));

      // Applying after middlewares
      routeMiddlewares = routeMiddlewares.concat(after);

      // Determining the method
      var methods = [].concat(route.method || route.methods || 'ALL');

      methods.forEach(function(method) {
        router[method.toLowerCase()].apply(
          router,
          [route.url]
            .concat(routeMiddlewares)
            .concat(route.action)
        );
      });
    });

    return router;
  }

  // Returning an object to handle
  return {
    router: makeRouter
  };
};
<commit_msg>Implement HTTP cache middle in app.<commit_after>/**
 * Dolman API Endpoint
 * ====================
 *
 * Exposing the library's utilities.
 */
var responses = require('./src/responses.js'),
    middlewares = require('./src/middlewares.js'),
    Typology = require('typology'),
    util = require('util');

module.exports = function(express, opts) {
  opts = opts || {};

  // Applying responses to express
  responses(express);

  // Building internal typology
  var types;

  if (opts.typology instanceof Typology)
    types = opts.typology;
  else
    types = new Typology(opts.typology || {});

  // Internal RAM cache
  var ramCache = {};

  // Building the router function
  function makeRouter(routes, o) {
    o = o || {};

    var router = express.Router(),
        after = [].concat(o.after || []);

    routes.forEach(function(route) {
      if (!route.url)
        throw Error('dolman.router: one route has no url: ' + util.inspect(route));

      if (!route.action)
        throw Error('dolman.router: the route for url ' + route.url + ' has no action.');

      // Applying before middlewares
      var routeMiddlewares = [];

      // Validation
      if (route.validate)
        routeMiddlewares.push(middlewares.validate(types, route.validate));

      // RAM cache
      if (route.ramCache)
        routeMiddlewares.push(middlewares.ramCache(ramCache, route.ramCache));

      // HTTP cache
      if (route.httpCache)
        routeMiddlewares.push(middlewares.httpCache(route.httpCache));

      // Applying after middlewares
      routeMiddlewares = routeMiddlewares.concat(after);

      // Determining the method
      var methods = [].concat(route.method || route.methods || 'ALL');

      methods.forEach(function(method) {
        router[method.toLowerCase()].apply(
          router,
          [route.url]
            .concat(routeMiddlewares)
            .concat(route.action)
        );
      });
    });

    return router;
  }

  // Returning an object to handle
  return {
    router: makeRouter
  };
};

{'fraction_non_alphanumeric': 0.14274789701758858, 'fraction_numerical': 0.0, 'mean_word_length': 2.5447154471544717, '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': '2778789', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1126, 'n_words': 267}