spee.ch/routes/serve-routes.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-06-14 00:49:58 +02:00
module.exports = function(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId){
2017-06-13 20:00:50 +02:00
// route to fetch one free public claim
app.get("/:name/:claim_id", function(req, res){
ua(googleAnalyticsId, {https: true}).event("Serve Route", "/name/claimId", req.params.name + "/" + req.params.claim_id).send();
var uri = req.params.name + "#" + req.params.claim_id;
console.log(">> GET request on /" + uri);
// create promise
2017-06-14 00:49:58 +02:00
lbryHelpers.getClaimBasedOnUri(uri)
2017-06-13 20:00:50 +02:00
.then(function(filePath){
console.log("/:name/:claim_id success.");
res.status(200).sendFile(filePath);
})
.catch(function(error){
console.log("/:name/:claim_id error:", error)
routeHelpers.handleRequestError(error, res);
});
});
// route to fetch one free public claim
app.get("/:name", function(req, res){
ua(googleAnalyticsId, {https: true}).event("Serve Route", "/name", req.params.name).send();
console.log(">> GET request on /" + req.params.name);
// create promise
2017-06-14 00:49:58 +02:00
lbryHelpers.getClaimBasedOnNameOnly(req.params.name)
2017-06-13 20:00:50 +02:00
.then(function(filePath){
console.log("/:name success.")
res.status(200).sendFile(filePath);
}).catch(function(error){
console.log("/:name error:", error);
routeHelpers.handleRequestError(error, res);
});
});
}