<commit_before>var debug = require('debug')('revo:router'),
	express = require('express'),
    router = express.Router(),
	_ = require('underscore');

const ERROR = require('chalk').red.bold;
const WARN = require('chalk').yellow.bold;
const INFO = require('chalk').green;

module.exports = router;

//todo: refactor this into a revo component
process.on('http.route:create', function(payload){
	debug('registered new dynamic route:', payload.path);
	if(!!payload.path) {
		router.route(payload.path).get(function (req, res, next) {
			if(!!payload.trigger) {
				//todo: add x-headers & query data
				//todo: move this block into sendFile's callback
				var reqData = req.params
				setTimeout(function(){
					process.emit(payload.trigger, reqData);
				}, 500);
			}
			if(payload.webpage) {
// 				var fullPath = [__dirname, '..', 'public', (payload.webpage=='/')?'index.html':payload.webpage].join('/');
// 				fullPath = 'index.html';
// 				var options = {
// 					root: __dirname + '/public/',
// 					dotfiles: 'deny',
// 					headers: {
// 					    'x-timestamp': Date.now(),
// 					    'x-sent': true
// 					}
// 				};				
// 				res.sendFile(fullPath, options, function(err){
// 					if(err) debug(ERROR(err));
					// process.emit(payload.trigger, reqData);
// 				})
				res.redirect(payload.webpage);
			}
			else res.end();
			next();
		});
	}
})

// //TODO
// router.use('test', function (req, res, next) {
// 	debug('intercepting component load:', req.params.component)	
// 	// console.log('Time: ', Date.now());
// 	next();
// });

// router.get('/components', function (req, res, next) {
// 	next();
// });

<commit_msg>structure change of the route event payload<commit_after>var debug = require('debug')('revo:router'),
	express = require('express'),
    router = express.Router(),
	_ = require('underscore');

const ERROR = require('chalk').red.bold;
const WARN = require('chalk').yellow.bold;
const INFO = require('chalk').green;

module.exports = router;

//todo: refactor this into a revo component
process.on('http.route:create', function(payload){
	debug('registered new dynamic route:', payload.path);
	if(!!payload.path) {
		router.route(payload.path).get(function (req, res, next) {
			if(!!payload.trigger) {
				//todo: move this block into sendFile's callback
				var reqData = { path: req.params[0], data: {} };
				Object.keys(req.query).forEach(function(key){
					reqData.data[key] = req.query[key];
				})
				//todo: add x-headers
				setTimeout(function(){
					process.emit(payload.trigger, reqData);
				}, 500);
			}
			if(payload.webpage) {
// 				var fullPath = [__dirname, '..', 'public', (payload.webpage=='/')?'index.html':payload.webpage].join('/');
// 				fullPath = 'index.html';
// 				var options = {
// 					root: __dirname + '/public/',
// 					dotfiles: 'deny',
// 					headers: {
// 					    'x-timestamp': Date.now(),
// 					    'x-sent': true
// 					}
// 				};				
// 				res.sendFile(fullPath, options, function(err){
// 					if(err) debug(ERROR(err));
					// process.emit(payload.trigger, reqData);
// 				})
				res.redirect(payload.webpage);
			}
			else res.end();
			next();
		});
	}
})

// //TODO
// router.use('test', function (req, res, next) {
// 	debug('intercepting component load:', req.params.component)	
// 	// console.log('Time: ', Date.now());
// 	next();
// });

// router.get('/components', function (req, res, next) {
// 	next();
// });


{'fraction_non_alphanumeric': 0.2078832116788321, 'fraction_numerical': 0.0020437956204379564, 'mean_word_length': 2.947004608294931, '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': '2073904', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1183, 'n_words': 225}