<commit_before>'use strict';

var _ = require('underscore');
var _s = require('underscore.string');
var factory = require('./factory');

/**
 * @param {String} root
 */
exports.setRoot = function (root) {
	factory.setRoot(root);
};

exports.entity = factory.get;
exports.entityConstructor = factory.getConstructor;
exports.fromJson = require('./from-json');


/**
 * @param {Request} req
 * @param {Response} res
 * @param {Function} callback
 */
exports.serveEntity = function (req, res, callback) {

	var namespace = _s.trim(req.url, '/').replace(/\.js$/g, '');

	return factory.getClientJsModificationTime(namespace, function (error, result) {
		if (error !== null) {
			callback(error);
		} else {
			res.set('Last-Modified', result);
			if (req.fresh) {
				res.status(304).end();
			} else {
				factory.getClientJs(namespace, function (error, content) {
					if (error !== null) {
						callback(error);
					} else {
						res.set('Content-Type', 'text/javascript');
						res.set('Content-Length', content.length);
						res.end(content);
					}
				});
			}
		}
	});

};<commit_msg>Refactored to use Express power<commit_after>'use strict';

var _s = require('underscore.string');
var factory = require('./factory');

/**
 * @param {String} root
 */
exports.setRoot = function (root) {
	factory.setRoot(root);
};

exports.entity = factory.get;
exports.entityConstructor = factory.getConstructor;
exports.fromJson = require('./from-json');


/**
 * @param {ExpressServerRequest} req
 * @param {ExpressServerResponse} res
 * @param {Function} callback
 */
exports.serveEntity = function (req, res, callback) {

	var namespace = _s.trim(req.url, '/').replace(/\.js$/g, '');

	return factory.getClientJsModificationTime(namespace, function (error, result) {
		if (error !== null) {
			callback(error);
		} else {
			res.set('Last-Modified', result);
			if (req.fresh) {
				res.send(304);
			} else {
				factory.getClientJs(namespace, function (error, content) {
					if (error !== null) {
						callback(error);
					} else {
						res.set('Content-Type', 'text/javascript');
						res.set('Content-Length', content.length);
						res.send(content);
					}
				});
			}
		}
	});

};
{'fraction_non_alphanumeric': 0.18036529680365296, 'fraction_numerical': 0.0027397260273972603, 'mean_word_length': 3.545643153526971, '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': '4685856', 'n_tokens_mistral': 821, 'n_tokens_neox': 695, 'n_words': 144}