diff --git a/server.js b/server.js index d8c634c..30822d3 100644 --- a/server.js +++ b/server.js @@ -56,25 +56,40 @@ app.set('view engine', 'hbs'); app.set('views', __dirname + '/views'); app.get('/', function(req, res){ - db.all("SELECT coreId, coreName, published_at FROM Alerts GROUP BY coreId, coreName, published_at;", function(err, rows){ - //console.log(rows); - res.render('index', {cores: rows}, function(err, html) { - res.send(html); + var d = new Date(); + console.log("GET /, " + JSON.stringify(d, 4)); + db.all("SELECT coreId, coreName, locationDesc FROM Alerts GROUP BY coreId, coreName, locationDesc;", function(err, rows){ + if(err !== null) { + console.log(err); + } else { + //console.log(rows); + res.render('index', {cores: rows}, function(err, html) { + if(err !== null) { + console.log(err); + } else { + res.send(html); + } + }); + } }); }); -// not sure if this ':id' notaction is correct app.get('/core/:id', function(req, res){ //res.sendFile("/usr/src/app/index.html"); //fs.createReadStream('./log.log').pipe(res); var d = new Date(); - console.log("GET request at, " + JSON.stringify(d, 4)); - // add WHERE clause w/core ID value from URL - db.all("SELECT coreId, published_at FROM Alerts ORDER BY published_at DESC LIMIT 30;", function(err, rows){ - //console.log(rows); - res.render('core', {alerts: rows}, function(err, html) { - res.send(html); - }); + var coreId = req.params.id; + console.log("GET /core/" + coreId + ", " + JSON.stringify(d, 4)); + db.all("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;", function(err, rows){ + if(err !== null) { + console.log(err); + } else { + console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;"); + console.log(rows); + res.render('core', {alerts: rows}, function(err, html) { + res.send(html); + }); + } }); //res.send; }); diff --git a/views/default.hbs b/views/default.hbs index bce3f17..3b0b564 100644 --- a/views/default.hbs +++ b/views/default.hbs @@ -1,30 +1,27 @@
- {{! Document Settings }} - {{! Page Meta }} -