Remove remaining sqlite code; do all logging thru winston.
This commit is contained in:
parent
fd746d5523
commit
6099fbd24a
24
server.js
24
server.js
@ -3,7 +3,6 @@ var hbs = require('express-hbs');
|
|||||||
require('handlebars-form-helpers').register(hbs.handlebars);
|
require('handlebars-form-helpers').register(hbs.handlebars);
|
||||||
var nodemailer = require('nodemailer');
|
var nodemailer = require('nodemailer');
|
||||||
var courtsopenUtils = require('./courtsopenUtils.js');
|
var courtsopenUtils = require('./courtsopenUtils.js');
|
||||||
var fs = require("fs");
|
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var app = express();
|
var app = express();
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
@ -24,16 +23,6 @@ var mailOptions = {
|
|||||||
subject: 'Device did not wish me a GoodMorning or GoodEvening',
|
subject: 'Device did not wish me a GoodMorning or GoodEvening',
|
||||||
};
|
};
|
||||||
|
|
||||||
var file = "./db/courtsopen.db";
|
|
||||||
var exists = fs.existsSync(file);
|
|
||||||
|
|
||||||
if(!exists) {
|
|
||||||
console.log("Creating DB file.");
|
|
||||||
fs.openSync(file, "w");
|
|
||||||
}
|
|
||||||
|
|
||||||
var sqlite3 = require("sqlite3").verbose();
|
|
||||||
var db = new sqlite3.Database(file);
|
|
||||||
var pg = require("pg");
|
var pg = require("pg");
|
||||||
var conString = "postgres://courtsopen:courtsopen@db/courtsopen";
|
var conString = "postgres://courtsopen:courtsopen@db/courtsopen";
|
||||||
|
|
||||||
@ -49,11 +38,10 @@ app.set('views', __dirname + '/views');
|
|||||||
|
|
||||||
app.get('/', function(req, res){
|
app.get('/', function(req, res){
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
console.log("GET /, " + JSON.stringify(d, 4));
|
|
||||||
winston.info("GET /");
|
winston.info("GET /");
|
||||||
pg.connect(conString, function(err, client, done) {
|
pg.connect(conString, function(err, client, done) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return console.error('error fetching client from pool', err);
|
return winston.error('error fetching client from pool', err);
|
||||||
}
|
}
|
||||||
var devIndexQry =
|
var devIndexQry =
|
||||||
"select status, published_at " +
|
"select status, published_at " +
|
||||||
@ -65,7 +53,7 @@ app.get('/', function(req, res){
|
|||||||
//call `done()` to release the client back to the pool
|
//call `done()` to release the client back to the pool
|
||||||
done();
|
done();
|
||||||
if(err) {
|
if(err) {
|
||||||
return console.error('error running query', err);
|
return winston.error('error running query', err);
|
||||||
}
|
}
|
||||||
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
||||||
result.rows.forEach(function(row){
|
result.rows.forEach(function(row){
|
||||||
@ -78,7 +66,7 @@ app.get('/', function(req, res){
|
|||||||
|
|
||||||
res.render('index', {values: result.rows}, function(err, html) {
|
res.render('index', {values: result.rows}, function(err, html) {
|
||||||
if(err !== null) {
|
if(err !== null) {
|
||||||
console.log(err);
|
winston.error(err);
|
||||||
} else {
|
} else {
|
||||||
res.send(html);
|
res.send(html);
|
||||||
}
|
}
|
||||||
@ -90,7 +78,7 @@ app.get('/', function(req, res){
|
|||||||
app.post('/', function(req, res){
|
app.post('/', function(req, res){
|
||||||
var postEvent = req.body.postEvent;
|
var postEvent = req.body.postEvent;
|
||||||
var source = req.body.source;
|
var source = req.body.source;
|
||||||
console.log(req.body);
|
winston.info(req.body);
|
||||||
|
|
||||||
// If it's stripped down JSON sent by cell modem, there won't be a req.body.data key w/full-nested JSON as value!!!
|
// If it's stripped down JSON sent by cell modem, there won't be a req.body.data key w/full-nested JSON as value!!!
|
||||||
// ???how to fix???
|
// ???how to fix???
|
||||||
@ -101,7 +89,7 @@ app.post('/', function(req, res){
|
|||||||
var coreid = JSON.stringify(req.body.coreid, null, 4).slice(1,-1);
|
var coreid = JSON.stringify(req.body.coreid, null, 4).slice(1,-1);
|
||||||
var pubAt = JSON.stringify(req.body.published_at, null, 4).slice(1,-1);
|
var pubAt = JSON.stringify(req.body.published_at, null, 4).slice(1,-1);
|
||||||
pg.connect(conString, function(err, client, done) {
|
pg.connect(conString, function(err, client, done) {
|
||||||
if(err) { return console.error('error fetching client from pool', err); }
|
if(err) { return winston.error('error fetching client from pool', err); }
|
||||||
client.query(
|
client.query(
|
||||||
"INSERT INTO alerts (origjson, coreid, published_at, status) VALUES ($1, $2, $3, $4);",
|
"INSERT INTO alerts (origjson, coreid, published_at, status) VALUES ($1, $2, $3, $4);",
|
||||||
[JSON.stringify(req.body, null, 4), coreid, pubAt, status]
|
[JSON.stringify(req.body, null, 4), coreid, pubAt, status]
|
||||||
@ -122,7 +110,7 @@ app.post('/', function(req, res){
|
|||||||
received_at = received_at.toISOString();
|
received_at = received_at.toISOString();
|
||||||
winston.info(statusFromCode + ' ' + received_at);
|
winston.info(statusFromCode + ' ' + received_at);
|
||||||
pg.connect(conString, function(err, client, done) {
|
pg.connect(conString, function(err, client, done) {
|
||||||
if(err) { return console.error('error fetching client from pool', err); }
|
if(err) { return winston.error('error fetching client from pool', err); }
|
||||||
client.query(
|
client.query(
|
||||||
"INSERT INTO alerts (origjson, coreid, published_at, status) VALUES ($1, $2, $3, $4);",
|
"INSERT INTO alerts (origjson, coreid, published_at, status) VALUES ($1, $2, $3, $4);",
|
||||||
[JSON.stringify(req.body, null, 4), deviceid, received_at, statusFromCode]
|
[JSON.stringify(req.body, null, 4), deviceid, received_at, statusFromCode]
|
||||||
|
Loading…
Reference in New Issue
Block a user