Allow flows file to be set in settings

This commit is contained in:
Nicholas O'Leary 2013-10-04 17:28:15 +01:00
parent 18e76364fc
commit ef0e5b98c2
3 changed files with 16 additions and 9 deletions

2
red.js
View File

@ -48,6 +48,8 @@ if (settings.httpAuth) {
);
}
settings.flowfile = process.argv[2] || settings.flowfile;
var red = RED.init(server,settings);
app.use(settings.httpRoot,red);

View File

@ -18,9 +18,9 @@ var fs = require('fs');
var util = require('util');
var createUI = require("./ui");
var redNodes = require("./nodes");
var host = require('os').hostname();
//TODO: relocated user dir
var rulesfile = process.argv[2] || 'flows_'+host+'.json';
var flowfile = '';
var app = null;
var server = null;
@ -29,6 +29,8 @@ function createServer(_server,settings) {
server = _server;
app = createUI(settings);
flowfile = settings.flowfile || 'flows_'+require('os').hostname()+'.json';
//TODO: relocated user dir
fs.exists("lib/",function(exists) {
if (!exists) {
@ -43,9 +45,9 @@ function createServer(_server,settings) {
});
app.get("/flows",function(req,res) {
fs.exists(rulesfile, function (exists) {
fs.exists(flowfile, function (exists) {
if (exists) {
res.sendfile(rulesfile);
res.sendfile(flowfile);
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("[]");
@ -62,7 +64,7 @@ function createServer(_server,settings) {
req.on('end', function() {
res.writeHead(204, {'Content-Type': 'text/plain'});
res.end();
fs.writeFile(rulesfile, fullBody, function(err) {
fs.writeFile(flowfile, fullBody, function(err) {
if(err) {
util.log(err);
} else {
@ -87,14 +89,14 @@ function start() {
util.log("------------------------------------------");
fs.exists(rulesfile, function (exists) {
fs.exists(flowfile, function (exists) {
if (exists) {
util.log("[red] Loading flows : "+rulesfile);
fs.readFile(rulesfile,'utf8',function(err,data) {
util.log("[red] Loading flows : "+flowfile);
fs.readFile(flowfile,'utf8',function(err,data) {
redNodes.setConfig(JSON.parse(data));
});
} else {
util.log("[red] Flows file not found : "+rulesfile);
util.log("[red] Flows file not found : "+flowfile);
}
});
}

View File

@ -19,6 +19,9 @@ module.exports = {
serialReconnectTime: 15000,
debugMaxLength: 1000,
// The file containing the flows. If not set, it defaults to flows_<hostname>.json
//flowfile: 'flows.json'
// You can protect the user interface with a userid and password by using the following property
// the password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password')
//httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"},