Created
July 10, 2015 17:52
-
-
Save ericnakagawa/3a35018036c93a989c29 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
app.get('/:url', function(req, res) { | |
var Link = Parse.Object.extend("Link"); | |
var url = req.params.url; | |
var query1 = new Parse.Query(Link); | |
query1.equalTo("shorturl", req.params.url); | |
var query2 = new Parse.Query(Link); | |
query2.equalTo("longurl", req.params.url); | |
var query3 = new Parse.Query(Link); | |
query3.equalTo("longhyphenurl", req.params.url); | |
var mainQuery = Parse.Query.or(query1, query2, query3); | |
mainQuery.descending("createdAt"); | |
mainQuery.first().then(function(link){ | |
if(link) { | |
link.increment("views"); | |
link.save().then(function(success) { | |
res.redirect(link.get("url")); | |
}, function(error) { | |
res.redirect(link.get("url")) | |
}); | |
} else { | |
res.redirect("/"); | |
} | |
}, function(error) { | |
res.send("error"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment