better config implementation from ENV or json file.
using new environment; params passed as docker-compose params
This commit is contained in:
42
dht.js
42
dht.js
@@ -1,5 +1,17 @@
|
||||
// ./src/index.js
|
||||
var config = require('./src/setup_const');
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
console.log("ENV: %s", env);
|
||||
const config = require(__dirname + '/config/config.json')[env];
|
||||
|
||||
(function() {
|
||||
var exLog = console.log;
|
||||
console.log = function(msg) {
|
||||
exLog.apply(this, arguments);
|
||||
fs.appendFileSync(config.logFile, msg +"\r\n");
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
// importing the dependencies
|
||||
const util = require('util');
|
||||
@@ -83,7 +95,7 @@ app.post('/accontrol',
|
||||
//break it
|
||||
//code = code.substring(150);
|
||||
//console.log("RAW: " + code);
|
||||
if(ir.SendCmd("http://"+AcIP, code))
|
||||
if(ir.SendCmd("http://"+config.AcIP, code))
|
||||
{
|
||||
console.log("OK. Temp: " + req.body.temp);
|
||||
BroadcastWS(ac.Tlc112.GetState());
|
||||
@@ -120,16 +132,19 @@ app.use('/waterTest',function(req, res){
|
||||
|
||||
console.log("Watering TEST for: " + req.params);
|
||||
});
|
||||
|
||||
config.gardenIP = process.env.GARDEN_IP || config.gardenIP
|
||||
|
||||
app.use('/water',function(req, res){
|
||||
var time = req.query.t;
|
||||
console.log("Watering cmd for: " + time);
|
||||
request('http://'+config.GardenIP+'/tools?cmd=event,manualwatering='+ time, { json: true }, (err, res, body) => {
|
||||
request('http://'+config.gardenIP+'/tools?cmd=event,manualwatering='+ time, { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log("Problem watering: " + err); }
|
||||
console.log("Watering cmd successfully sent!");
|
||||
});
|
||||
});
|
||||
app.use('/waterStop',function(req, res){
|
||||
request('http://'+config.GardenIP+'/tools?cmd=event,stopwatering', { json: true }, (err, res, body) => {
|
||||
request('http://'+config.gardenIP+'/tools?cmd=event,stopwatering', { json: true }, (err, res, body) => {
|
||||
if (err) { return console.log("Problem watering: " + err); }
|
||||
console.log("STOP watering cmd sent!");
|
||||
});
|
||||
@@ -161,6 +176,7 @@ app.put('/device/:device_id/:field_name/:field_value', (req, res) => {
|
||||
|
||||
//!Startup
|
||||
|
||||
var wws;
|
||||
if(credentials){
|
||||
var httpsServer = https.createServer(credentials, app);
|
||||
httpsServer.listen(2443, () => {
|
||||
@@ -175,6 +191,7 @@ else
|
||||
console.log('HTTP server listening on port 2080');
|
||||
});
|
||||
wss = new WebSocket.Server({ port: 2081 });//not secure
|
||||
console.log('WebSocket server listening on port 2081');
|
||||
}
|
||||
|
||||
// // # ┌────────────── second (optional)
|
||||
@@ -194,25 +211,14 @@ else
|
||||
|
||||
//db.devicemessages.getFromDht('http://192.168.1.126/json');
|
||||
|
||||
wss.on('connection', ws => {
|
||||
ws.on('message', message => {
|
||||
wss.on('connection', wss => {
|
||||
wss.on('message', message => {
|
||||
console.log('Received message => ${message}');
|
||||
});
|
||||
ws.send('ho!');
|
||||
wss.send('ho!');
|
||||
});
|
||||
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const cfg = require(__dirname + '/config/config.json')[env];
|
||||
|
||||
(function() {
|
||||
var exLog = console.log;
|
||||
console.log = function(msg) {
|
||||
exLog.apply(this, arguments);
|
||||
fs.appendFileSync(cfg.logFile, msg +"\r\n");
|
||||
}
|
||||
})();
|
||||
|
||||
// const {keys} = Object;
|
||||
// const {Console} = console;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user