2016-06-23 12:17:39 +09:00
|
|
|
import Posts from '../collection.js';
|
2015-09-18 16:27:59 +09:00
|
|
|
|
|
|
|
Picker.route('/out', function(params, req, res, next) {
|
|
|
|
var query = params.query;
|
|
|
|
if(query.url){ // for some reason, query.url doesn't need to be decoded
|
|
|
|
var post = Posts.findOne({url: query.url});
|
|
|
|
if (post) {
|
2016-07-06 10:21:58 +09:00
|
|
|
var ip = req.headers && req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
2016-06-23 11:40:35 +09:00
|
|
|
Posts.methods.increaseClicks(post._id, ip);
|
2015-09-18 16:27:59 +09:00
|
|
|
res.writeHead(302, {'Location': query.url});
|
|
|
|
res.end();
|
|
|
|
} else {
|
|
|
|
// don't redirect if we can't find a post for that link
|
|
|
|
res.end('Invalid URL');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.end("Please provide a URL");
|
|
|
|
}
|
|
|
|
});
|