aboutsummaryrefslogtreecommitdiff
path: root/diller.js
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-10-18 18:10:20 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-10-18 18:10:20 +0200
commit52eb8072664a61ea61dbdbef7485d6c81dbbcfe9 (patch)
treef4218bc276a0188da26da472d1233c264ff31dfe /diller.js
parent9339e6269d6f5a5d0421c23c5e9ba3c8500fb535 (diff)
downloaddiller-server-52eb8072664a61ea61dbdbef7485d6c81dbbcfe9.tar.gz
diller-server-52eb8072664a61ea61dbdbef7485d6c81dbbcfe9.tar.bz2
diller-server-52eb8072664a61ea61dbdbef7485d6c81dbbcfe9.tar.xz
diller-server-52eb8072664a61ea61dbdbef7485d6c81dbbcfe9.zip
o Dropping the app concept.
o Switching to pg-promise to not get overloaded by callbacks.
Diffstat (limited to 'diller.js')
-rw-r--r--diller.js41
1 files changed, 4 insertions, 37 deletions
diff --git a/diller.js b/diller.js
index aaad6c1..cfaa6a7 100644
--- a/diller.js
+++ b/diller.js
@@ -1,9 +1,6 @@
var mqtt = require('mqtt');
var fs = require('fs');
-var _ = require('underscore');
-var winston = require('winston');
var bunyan = require('bunyan');
-var pg = require('pg');
var config = require('./src/config');
@@ -27,7 +24,7 @@ function configureLogging(config) {
var stat;
try {
stat = fs.lstatSync('log');
- } catch(e) {
+ } catch (e) {
// Assume this to to be ENOENT
fs.mkdirSync('log');
}
@@ -41,35 +38,9 @@ function configureLogging(config) {
var log = configureLogging(config);
-var pgClient = new pg.Client(config.postgresqlUrl);
-pgClient.connect();
-pgClient.on('connect', function () {
- log.info('connected to pg');
-});
-
-var apps = [
- './apps/logger',
- './apps/device',
- './apps/values'
-];
-
-appConfig = {
- pg: {
- connect: function (cb) {
- pg.connect(config.postgresqlUrl, cb);
- }
- }
-};
-
-apps = _.map(apps, function (name) {
- log.info('Loading app: ' + name);
- var app = require(name);
- var cfg = _.clone(appConfig);
+var Diller = require('./src/Diller').Diller;
- cfg.log = log.child({app: name});
- app.init(cfg);
- return {name: name, instance: app};
-});
+var diller = new Diller(config, log);
log.info('Connecting to ' + config.mqttUrl);
var mqttClient = mqtt.connect(config.mqttUrl);
@@ -88,9 +59,5 @@ mqttClient.on('connect', function () {
});
mqttClient.on('message', function (topic, message, payload) {
- log.info('got message', {message: message.toString()});
-
- _.each(apps, function (app) {
- app.instance.onMessage(topic, message, payload);
- });
+ diller.onMessage(topic, message, payload);
});