2017-05-24 20:07:43 +02:00
|
|
|
var path = require('path');
|
2017-06-03 09:41:02 +02:00
|
|
|
var routeHelpers = require('../helpers/routeHelpers.js');
|
2017-05-24 20:07:43 +02:00
|
|
|
var lbryApi = require('../helpers/lbryApi.js');
|
|
|
|
|
|
|
|
module.exports = function(app){
|
2017-06-11 03:33:03 +02:00
|
|
|
// route for favicon
|
|
|
|
// app.get("/favicon.ico", function(req, res){
|
|
|
|
// console.log(" >> GET request on favicon.ico");
|
|
|
|
// res.sendFile(path.join(__dirname, '../public/assets/img', 'favicon.ico'));
|
|
|
|
// });
|
2017-05-24 20:07:43 +02:00
|
|
|
// route to fetch one free public claim
|
|
|
|
app.get("/:name/all", function(req, res){
|
2017-06-03 05:56:33 +02:00
|
|
|
console.log(">> GET request on /" + req.params.name + " (all)");
|
2017-06-01 02:00:13 +02:00
|
|
|
// create promise
|
2017-06-03 05:56:33 +02:00
|
|
|
lbryApi.getAllClaims(req.params.name)
|
|
|
|
.then(function(orderedFreePublicClaims){
|
2017-06-10 01:46:57 +02:00
|
|
|
console.log("/:name/all success.");
|
|
|
|
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
|
2017-06-01 01:44:45 +02:00
|
|
|
return;
|
|
|
|
})
|
|
|
|
.catch(function(error){
|
2017-06-03 05:56:33 +02:00
|
|
|
console.log("/:name/all error:", error);
|
2017-06-03 09:41:02 +02:00
|
|
|
routeHelpers.handleRequestError(error, res);
|
2017-06-01 01:44:45 +02:00
|
|
|
})
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
|
|
|
// route to fetch one free public claim
|
|
|
|
app.get("/:name/:claim_id", function(req, res){
|
2017-06-01 01:44:45 +02:00
|
|
|
var uri = req.params.name + "#" + req.params.claim_id;
|
|
|
|
console.log(">> GET request on /" + uri);
|
2017-06-01 02:00:13 +02:00
|
|
|
// create promise
|
2017-06-03 05:56:33 +02:00
|
|
|
lbryApi.getClaimBasedOnUri(uri)
|
|
|
|
.then(function(filePath){
|
|
|
|
console.log("/:name/:claim_id success.");
|
2017-06-01 01:44:45 +02:00
|
|
|
res.status(200).sendFile(filePath);
|
|
|
|
})
|
|
|
|
.catch(function(error){
|
2017-06-05 02:40:06 +02:00
|
|
|
console.log("/:name/:claim_id error:", error)
|
2017-06-03 09:41:02 +02:00
|
|
|
routeHelpers.handleRequestError(error, res);
|
2017-06-01 01:44:45 +02:00
|
|
|
});
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
|
|
|
// route to fetch one free public claim
|
|
|
|
app.get("/:name", function(req, res){
|
2017-06-03 05:56:33 +02:00
|
|
|
console.log(">> GET request on /" + req.params.name);
|
2017-06-01 02:00:13 +02:00
|
|
|
// create promise
|
2017-06-03 05:56:33 +02:00
|
|
|
lbryApi.getClaimBasedOnNameOnly(req.params.name)
|
|
|
|
.then(function(filePath){
|
|
|
|
console.log("/:name success.")
|
2017-06-01 01:44:45 +02:00
|
|
|
res.status(200).sendFile(filePath);
|
2017-06-03 05:56:33 +02:00
|
|
|
}).catch(function(error){
|
2017-06-05 02:40:06 +02:00
|
|
|
console.log("/:name error:", error);
|
2017-06-03 09:41:02 +02:00
|
|
|
routeHelpers.handleRequestError(error, res);
|
2017-06-01 01:44:45 +02:00
|
|
|
});
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
|
|
|
// route for the home page
|
|
|
|
app.get("/", function(req, res){
|
2017-06-10 01:46:57 +02:00
|
|
|
res.status(200).render('index');
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
|
|
|
// a catch-all route if someone visits a page that does not exist
|
|
|
|
app.use("*", function(req, res){
|
2017-06-10 01:46:57 +02:00
|
|
|
res.status(404).render('fourOhFour');
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
2017-05-26 11:25:44 +02:00
|
|
|
}
|