1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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); var red = RED.init(server,settings);
app.use(settings.httpRoot,red); app.use(settings.httpRoot,red);

View File

@ -18,9 +18,9 @@ var fs = require('fs');
var util = require('util'); var util = require('util');
var createUI = require("./ui"); var createUI = require("./ui");
var redNodes = require("./nodes"); var redNodes = require("./nodes");
var host = require('os').hostname();
//TODO: relocated user dir //TODO: relocated user dir
var rulesfile = process.argv[2] || 'flows_'+host+'.json';
var flowfile = '';
var app = null; var app = null;
var server = null; var server = null;
@ -29,6 +29,8 @@ function createServer(_server,settings) {
server = _server; server = _server;
app = createUI(settings); app = createUI(settings);
flowfile = settings.flowfile || 'flows_'+require('os').hostname()+'.json';
//TODO: relocated user dir //TODO: relocated user dir
fs.exists("lib/",function(exists) { fs.exists("lib/",function(exists) {
if (!exists) { if (!exists) {
@ -43,9 +45,9 @@ function createServer(_server,settings) {
}); });
app.get("/flows",function(req,res) { app.get("/flows",function(req,res) {
fs.exists(rulesfile, function (exists) { fs.exists(flowfile, function (exists) {
if (exists) { if (exists) {
res.sendfile(rulesfile); res.sendfile(flowfile);
} else { } else {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("[]"); res.write("[]");
@ -62,7 +64,7 @@ function createServer(_server,settings) {
req.on('end', function() { req.on('end', function() {
res.writeHead(204, {'Content-Type': 'text/plain'}); res.writeHead(204, {'Content-Type': 'text/plain'});
res.end(); res.end();
fs.writeFile(rulesfile, fullBody, function(err) { fs.writeFile(flowfile, fullBody, function(err) {
if(err) { if(err) {
util.log(err); util.log(err);
} else { } else {
@ -87,14 +89,14 @@ function start() {
util.log("------------------------------------------"); util.log("------------------------------------------");
fs.exists(rulesfile, function (exists) { fs.exists(flowfile, function (exists) {
if (exists) { if (exists) {
util.log("[red] Loading flows : "+rulesfile); util.log("[red] Loading flows : "+flowfile);
fs.readFile(rulesfile,'utf8',function(err,data) { fs.readFile(flowfile,'utf8',function(err,data) {
redNodes.setConfig(JSON.parse(data)); redNodes.setConfig(JSON.parse(data));
}); });
} else { } 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, serialReconnectTime: 15000,
debugMaxLength: 1000, 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 // 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') // the password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password')
//httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"}, //httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"},