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