diff --git a/helpers/routeHelpers.js b/helpers/routeHelpers.js index 6aa294c4..f3f43814 100644 --- a/helpers/routeHelpers.js +++ b/helpers/routeHelpers.js @@ -3,7 +3,7 @@ var path = require('path'); module.exports = { handleRequestError: function(error, res) { if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ - res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + res.status(307).render('noClaims'); } else if (error.response){ res.status(error.response.status).send(error.response.data.error.message); } else if (error.code === "ECONNREFUSED") { diff --git a/package.json b/package.json index 2300bd02..799ceade 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "axios": "^0.16.1", "body-parser": "^1.17.1", "express": "^4.15.2", + "express-handlebars": "^3.0.0", "nodemon": "^1.11.0", "socket.io": "^2.0.1", "socketio-file-upload": "^0.6.0" diff --git a/public/assets/css/style.css b/public/assets/css/style.css index e69de29b..88ef37b6 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -0,0 +1,3 @@ +.all-claims-img { + height: 200px; +} \ No newline at end of file diff --git a/public/fourOhfour.html b/public/fourOhfour.html deleted file mode 100644 index 982f8678..00000000 --- a/public/fourOhfour.html +++ /dev/null @@ -1,14 +0,0 @@ - - -
- - - -That page does not exist. Return home.
- - \ No newline at end of file diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 71e0c3f0..00000000 --- a/public/index.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - -spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.
-If you would like to help make spee.ch amazing, join our slack channel.
-We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!
-Note: these are being used for testing durring spee.ch development and may not be maintained
-Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our github if you experience a problem or have suggestions.
-There are no free, public images at that claim. You should publish one at spee.ch.
- - \ No newline at end of file diff --git a/routes/html-routes.js b/routes/html-routes.js index 433a3bdc..dc6e2fb3 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -14,8 +14,8 @@ module.exports = function(app){ // create promise lbryApi.getAllClaims(req.params.name) .then(function(orderedFreePublicClaims){ - console.log("/:name/all success.") - res.status(200).send(orderedFreePublicClaims); + console.log("/:name/all success."); + res.status(200).render('allClaims', { claims: orderedFreePublicClaims }); return; }) .catch(function(error){ @@ -53,10 +53,10 @@ module.exports = function(app){ }); // route for the home page app.get("/", function(req, res){ - res.status(200).sendFile(path.join(__dirname, '../public', 'index.html')); + res.status(200).render('index'); }); // a catch-all route if someone visits a page that does not exist app.use("*", function(req, res){ - res.status(404).sendFile(path.join(__dirname, '../public', 'fourOhfour.html')); + res.status(404).render('fourOhFour'); }); } diff --git a/server.js b/server.js index abf98fba..63601032 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ var express = require('express'); var bodyParser = require('body-parser'); var path = require('path'); var siofu = require("socketio-file-upload"); +var expressHandlebars = require("express-handlebars"); // set port var PORT = 3000; @@ -14,16 +15,19 @@ var app = express(); app.use(express.static(__dirname + '/public')); // configure express app -app.use(bodyParser.json()); // for parsing application/json +app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(siofu.router); +// configure handlebars +app.engine('handlebars', expressHandlebars({defaultLayout: 'main'})); +app.set('view engine', 'handlebars'); + // require express routes require("./routes/api-routes.js")(app); require("./routes/html-routes.js")(app); -// include socket.io functionality -// this wraps the server in sockets, to intercept incoming sockets requests +// wrap the server in socket.io to intercept incoming sockets requests var http = require("./routes/sockets-routes.js")(app); // start server diff --git a/views/allClaims.handlebars b/views/allClaims.handlebars new file mode 100644 index 00000000..eb5b2adc --- /dev/null +++ b/views/allClaims.handlebars @@ -0,0 +1,12 @@ +These are all the free, public assets at that claim. You can publish more at spee.ch.
+ +{{#each claims}} +claim_id: {{this.claim_id}}
+direct link here
+author: {{this.value.stream.metadata.author}}
+description: {{this.value.stream.metadata.description}}
+license: {{this.value.stream.metadata.license}}
+{{/each}} diff --git a/views/fourOhFour.handlebars b/views/fourOhFour.handlebars new file mode 100644 index 00000000..587389d7 --- /dev/null +++ b/views/fourOhFour.handlebars @@ -0,0 +1,3 @@ +That page does not exist. Return home.
\ No newline at end of file diff --git a/views/index.handlebars b/views/index.handlebars new file mode 100644 index 00000000..3d829ea5 --- /dev/null +++ b/views/index.handlebars @@ -0,0 +1,100 @@ +spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.
+ +{{> examples}} +{{> publish}} +{{> links}} +{{> documentation}} +{{> bugs}} +{{> contribute}} + + + + diff --git a/public/invalidUri.html b/views/layouts/main.handlebars similarity index 67% rename from public/invalidUri.html rename to views/layouts/main.handlebars index a4b0673e..03760135 100644 --- a/public/invalidUri.html +++ b/views/layouts/main.handlebars @@ -4,11 +4,10 @@ -There is no claim at that URI.
+ {{{ body }}}