<commit_before>
var path = require('path');
var url = require('url');

var common = require('../common.js');
var utils = common.load('utils');

function deniedAcess(self) {
  self.emit('error', utils.httpError(400, new Error('Framework acess denied')) );
}

module.exports = function handle_piccoloRequest() {
  // get request handler
  var handler = requestHandlers[this.path[1]];

  // no handler, send 404 error to client
  if (handler === undefined) {
    return deniedAcess(this);
  }

  // execute handler and send file to client
  handler.call(this);
};

// create request handlers map
var requestHandlers = {};

// send client the core framework file
requestHandlers['framework.js'] = function () {
  var file = this.piccolo.build.client.read();
  this.send(file);
};

// send client the requested module and its dependencies
requestHandlers['modules'] = function () {
  // TODO: will be done in 0.4.0
};

// send client the requested presenter
requestHandlers['presenter'] = function () {

  // check path given in url query
  var filepath = this.url.query.path;
  if (filepath === undefined) {
    return deniedAcess(this);
  }<commit_msg>[feature] add too simple module request handler<commit_after>
var path = require('path');
var url = require('url');

var common = require('../common.js');
var utils = common.load('utils');

function deniedAcess(self) {
  self.emit('error', utils.httpError(400, new Error('Framework acess denied')) );
}

module.exports = function handle_piccoloRequest() {
  // get request handler
  var handler = requestHandlers[this.path[1]];

  // no handler, send 404 error to client
  if (handler === undefined) {
    return deniedAcess(this);
  }

  // execute handler and send file to client
  handler.call(this);
};

// create request handlers map
var requestHandlers = {};

// send client the core framework file
requestHandlers['framework.js'] = function () {
  var file = this.piccolo.build.client.read();
  this.send(file);
};

// send client the requested module and its dependencies
// TODO: this will be rewriten in 0.4.0
requestHandlers['modules'] = function () {

  // check path given in url query
  var filepath = this.url.query.name;
  if (filepath === undefined) {
    return deniedAcess(this);
  }

  // security: parse path independent
  filepath = path.resolve(this.piccolo.get('modules'), path.basename(filepath) + '.js');

  // check that presenter exist
  if (this.piccolo.build.modules.exist(filepath) === false) {
    return deniedAcess(this);
  }

  var file = this.piccolo.build.modules.read(filepath);
  this.send(file);
};

// send client the requested presenter
requestHandlers['presenter'] = function () {

  // check path given in url query
  var filepath = this.url.query.path;
  if (filepath === undefined) {
    return deniedAcess(this);
  }
{'fraction_non_alphanumeric': 0.13975817923186346, 'fraction_numerical': 0.007112375533428165, 'mean_word_length': 3.8921739130434783, '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': '7289411', 'n_tokens_mistral': 859, 'n_tokens_neox': 841, 'n_words': 252}