Exemplo n.º 1
0
app.get('/:link_id/analyze', function(req,res){
	
	var id = shortener.expand(req.params.link_id);
	
	data.getLink(id, function(err, link_object){
		if (err){
			console.log('There was an ERROR retrieving the link from redis');
		} else{
			//Get the analytics data for this link
			data.getLinkAnalytics(id, function(err, link_analytics){
				if (err){
					console.log('ERROR getting bulk analytics');
					res.redirect('404');
				} else{
					res.render('dashboard',{
						hits: link_analytics,
						linkObject: link_object,
						server_address: SERVER_ADDRESS
					});
				}
			});
		}
	});
	
});
Exemplo n.º 2
0
app.get('/:link_id', function(req, res){
	if (req.params.link_id == "favicon.ico"){
		res.render('index');
		return;
	}
	
	console.log(JSON.stringify(req.headers));
	
	console.log("Getting link: " + req.params.link_id);
	var id = shortener.expand(req.params.link_id);
	
	data.getLink(id, function(err, value){
		if (err){
			console.log('there was an error getting the link from redis')
		} else{
			//Redirect the user to the original 'unshortened' link. 
			//Do it first, so the user doesn't have to wait
			res.redirect(value.original_link);
			
			//Build the analytics object for this hit
			var linkHitObject = {
				IP: req.headers.host,
				browser: req.headers["user-agent"],
				OS: req.headers["user-agent"], //Need to parse out browser\OS from user-agent
				time: new Date(),
				referer: req.headers.referer,
			};
			
			//Store the hit object into redis, to keep track of hits and analytics
			data.saveLinkHit(id, linkHitObject);
			//Push the hit to every Dashboard page that's currently open on this particular link
			distributeUpdate(value.short_link, linkHitObject);
		}
	});
	
}); 
Exemplo n.º 3
0
router.get('/:id', function(req, res, next) {
    var id = Number(req.params['id']);
    urls.getLink(id, res);
});