From 098e4deebb3e2c16c5705df6334105aae29313b1 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Thu, 25 Jun 2015 14:05:20 -0400 Subject: [PATCH] Add basic handlebars view to show what's in DB. No fancy AJAX-style update of page; have to refresh page to see new data. --- package.json | 3 ++- server.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d9f475b..2a9a907 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "dependencies": { "body-parser": "^1.12.4", "express": "^4.12.4", - "sqlite3": "^3.0.8" + "sqlite3": "^3.0.8", + "express-hbs": "^0.8.4" }, "scripts": { "start": "node server.js" } } diff --git a/server.js b/server.js index 10b756c..13de886 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,5 @@ var express = require("express"); +var hbs = require('express-hbs'); var fs = require("fs"); var bodyParser = require("body-parser"); var app = express(); @@ -30,11 +31,24 @@ db.serialize(function() { }); app.use(bodyParser.json()); +// Use `.hbs` for extensions and find partials in `views/partials`. +app.engine('hbs', hbs.express4({ + partialsDir: __dirname + '/views/partials' +})); +app.set('view engine', 'hbs'); +app.set('views', __dirname + '/views'); app.get('/', function(req, res){ //res.sendFile("/usr/src/app/index.html"); - fs.createReadStream('./log.log').pipe(res); + //fs.createReadStream('./log.log').pipe(res); console.log("got a GET request..."); + db.all("SELECT coreId, published_at FROM Alerts", function(err, rows){ + console.log(rows); + res.render('home', {alerts: rows}, function(err, html) { + res.send(html); + }); + }); + //res.send; }); app.post('/', function(req, res){