-
-
Save anonymous/79e2f02e4db22d8d8890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Picker.route('/:shortURL', function (params, request, response, next) { | |
if (params.shortURL === 'favicon.ico') next(); | |
var location | |
, url = URLs.findOne({shortURL: params.shortURL}); | |
// Not found | |
if (!url) location = Meteor.absoluteUrl() + 'url/not-found'; | |
// For private links, go to client side to authorize the requester | |
else if (url.isPrivate) { | |
location = Meteor.absoluteUrl() + 'redirect/' + url.shortURL; | |
} | |
// For public links, record statistical data and process redirection | |
else { | |
var clientIP = (request.headers['x-forwarded-for'] || '').split(',')[0] | |
|| request.connection.remoteAddress | |
|| request.socket.remoteAddress | |
|| request.connection.socket.remoteAddress | |
, userAgent = request.headers['user-agent']; | |
// Record statistical data | |
Meteor.call('/visit/insert', url.shortURL, clientIP, userAgent); | |
location = url.targetURL; | |
} | |
response.writeHead(302, {'Location': location}); | |
response.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment