<commit_before>'use strict';

var path = process.cwd();
var ClickHandler = require(path + '/app/controllers/clickHandler.server.js');

module.exports = function (app, passport) {

	function isLoggedIn (req, res, next) {
		if (req.isAuthenticated()) {
			return next();
		} else {
			res.redirect('/login');
		}
	}

	var clickHandler = new ClickHandler();

	app.route('/')
		.get(isLoggedIn, function (req, res) {
			res.sendFile(path + '/public/index.html');
		});

	app.route('/login')
		.get(function (req, res) {
			res.sendFile(path + '/public/login.html');
		});

	app.route('/logout')
		.get(function (req, res) {
			req.logout();
			res.redirect('/login');
		});

	app.route('/profile')
		.get(isLoggedIn, function (req, res) {
			res.sendFile(path + '/public/profile.html');
		});

	app.route('/api/:id')
		.get(isLoggedIn, function (req, res) {
			res.json(req.user.github);
		});

	app.route('/auth/github')
		.get(passport.authenticate('github'));

	app.route('/auth/github/callback')
		.get(passport.authenticate('github', {
			successRedirect: '/',
			failureRedirect: '/login'
		}));

	app.route('/api/:id/clicks')
		.get(isLoggedIn, clickHandler.getClicks)
		.post(isLoggedIn, clickHandler.addClick)
		.delete(isLoggedIn, clickHandler.resetClicks);
};<commit_msg>Headers API<commit_after>'use strict';

var path = process.cwd();
var ClickHandler = require(path + '/app/controllers/clickHandler.server.js');

module.exports = function (app, passport) {

	function isLoggedIn (req, res, next) {
		if (req.isAuthenticated()) {
			return next();
		} else {
			res.redirect('/login');
		}
	}

	var clickHandler = new ClickHandler();
	

	app.route('/')
		.get(isLoggedIn, function (req, res) {
			res.sendFile(path + '/public/index.html');
		});

	app.route('/login')
		.get(function (req, res) {
			res.sendFile(path + '/public/login.html');
		});

	app.route('/logout')
		.get(function (req, res) {
			req.logout();
			res.redirect('/login');
		});

	app.route('/profile')
		.get(isLoggedIn, function (req, res) {
			res.sendFile(path + '/public/profile.html');
		});

	app.route('/api/:id')
		.get(isLoggedIn, function (req, res) {
			res.json(req.user.github);
		});

	app.route('/auth/github')
		.get(passport.authenticate('github'));

	app.route('/auth/github/callback')
		.get(passport.authenticate('github', {
			successRedirect: '/',
			failureRedirect: '/login'
		}));

	app.route('/api/:id/clicks')
		.get(isLoggedIn, clickHandler.getClicks)
		.post(isLoggedIn, clickHandler.addClick)
		.delete(isLoggedIn, clickHandler.resetClicks);


	// Added Routes for API projects //

	// Timestamp API project
	app.route('/timestamp')
		.get((req, res) => {
			res.sendFile(path + '/public/timestamp.html');
	});
	app.route('/timestamp/:query')
		.get((req, res) => {
		var queryDate = req.params.query,
		    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], 
		    dateObj = {};
	
		if(+queryDate){
			dateObj.unix = queryDate;
			var nDate = new Date(queryDate * 1000);
			dateObj.natural = months[nDate.getMonth()] + ' ' + nDate.getDate() + ', ' + nDate.getFullYear();	
		}else if(!isNaN(Date.parse(queryDate)) ){
			dateObj.unix = Date.parse(queryDate) / 1000;
			dateObj.natural = queryDate;
		}else{
			dateObj.unix = null;
			dateObj.natural = null;
		}
			
		res.end(JSON.stringify(dateObj));
	});
	
	// Headers API Project
	app.route('/headers')
		.get( (req, res) => {
			var headersObj = {},
			    reg = /(?:\()([\w\s\d;]+)(?:\))/,
		            userFiltered = reg.exec(req.headers['user-agent']);
			    
			
			headersObj.ip = req.headers['x-forwarded-for'],
			headersObj.lang = req.headers['accept-language'].split(',')[0],
			headersObj.software = userFiltered[1];
			
			res.end(JSON.stringify(headersObj));

	});
};
{'fraction_non_alphanumeric': 0.20428422152560083, 'fraction_numerical': 0.002612330198537095, 'mean_word_length': 3.591127098321343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5352483', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1367, 'n_words': 227}