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){
|
|
|
|
// route to fetch one free public claim
|
|
|
|
app.get("/favicon.ico", function(req, res){
|
|
|
|
console.log(" >> GET request on favicon.ico");
|
2017-06-03 05:56:33 +02:00
|
|
|
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){
|
|
|
|
console.log("/:name/all success.")
|
2017-06-01 01:44:45 +02:00
|
|
|
res.status(200).send(orderedFreePublicClaims);
|
|
|
|
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-03 05:56:33 +02:00
|
|
|
console.log("/:name/:claim_id 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){
|
|
|
|
console.log("/:name 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-01 01:44:45 +02:00
|
|
|
res.status(200).sendFile(path.join(__dirname, '../public', 'index.html'));
|
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-01 01:44:45 +02:00
|
|
|
res.status(404).sendFile(path.join(__dirname, '../public', 'fourOhfour.html'));
|
2017-05-24 20:07:43 +02:00
|
|
|
});
|
2017-05-26 11:25:44 +02:00
|
|
|
}
|