<commit_before>'use strict';

var _ = require('lodash');
var get = require('./get');
var post = require('./post');
var put = require('./put');
var del = require('./delete');
var url = require('url');
var path = require('path');

module.exports = function (models, config) {
	function middleware(req, res, next) {
		var parsed = url.parse(_.trim(req.originalUrl, path.sep));
		var urlPieces = parsed.pathname.split(path.sep);
		var method = req.method.toLowerCase();

		if (!urlPieces.length) {
			return next();
		}

		var modelName = null;
		var modelId = null;

		// Named model
		if (this && this.modelName) {
			modelName = this.modelName.toLowerCase();
			if (req.params && req.params.id) {
				modelId = req.params.id;
			}
		}
		// Model from URL
		else if (!models.hasOwnProperty(urlPieces[urlPieces.length - 1].toLowerCase())) {
				if (urlPieces.length < 2 || !models.hasOwnProperty(urlPieces[urlPieces.length - 2].toLowerCase())) {
					return next();
				} else {<commit_msg>Update middleware.js<commit_after>'use strict';

var _ = require('lodash');
var get = require('./get');
var post = require('./post');
var put = require('./put');
var del = require('./delete');
var url = require('url');
var path = require('path');

module.exports = function (models, config) {
	function middleware(req, res, next) {
		var parsed = url.parse(_.trim(req.originalUrl,'/'));
		var urlPieces = parsed.pathname.split('/');
		var method = req.method.toLowerCase();

		if (!urlPieces.length) {
			return next();
		}

		var modelName = null;
		var modelId = null;

		// Named model
		if (this && this.modelName) {
			modelName = this.modelName.toLowerCase();
			if (req.params && req.params.id) {
				modelId = req.params.id;
			}
		}
		// Model from URL
		else if (!models.hasOwnProperty(urlPieces[urlPieces.length - 1].toLowerCase())) {
				if (urlPieces.length < 2 || !models.hasOwnProperty(urlPieces[urlPieces.length - 2].toLowerCase())) {
					return next();
				} else {
{'fraction_non_alphanumeric': 0.17614213197969544, 'fraction_numerical': 0.003045685279187817, 'mean_word_length': 3.6485849056603774, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5066558', 'n_tokens_mistral': 726, 'n_tokens_neox': 665, 'n_words': 154}