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.
This commit is contained in:
		
							parent
							
								
									68256ab8e8
								
							
						
					
					
						commit
						098e4deebb
					
				@ -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" }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								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){
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user