mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add flow reload admin api
This commit is contained in:
parent
35c4a41d7b
commit
87d77efa57
@ -41,7 +41,8 @@
|
|||||||
|
|
||||||
"api": {
|
"api": {
|
||||||
"flows": {
|
"flows": {
|
||||||
"error-save": "Error saving flows: __message__"
|
"error-save": "Error saving flows: __message__",
|
||||||
|
"error-reload": "Error reloading flows: __message__"
|
||||||
},
|
},
|
||||||
"library": {
|
"library": {
|
||||||
"error-load-entry": "Error loading library entry '__path__': __message__",
|
"error-load-entry": "Error loading library entry '__path__': __message__",
|
||||||
|
@ -32,12 +32,22 @@ module.exports = {
|
|||||||
var flows = req.body;
|
var flows = req.body;
|
||||||
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
|
var deploymentType = req.get("Node-RED-Deployment-Type")||"full";
|
||||||
log.audit({event: "flows.set",type:deploymentType},req);
|
log.audit({event: "flows.set",type:deploymentType},req);
|
||||||
redNodes.setFlows(flows,deploymentType).then(function() {
|
if (deploymentType === 'reload') {
|
||||||
res.status(204).end();
|
redNodes.loadFlows().then(function() {
|
||||||
}).otherwise(function(err) {
|
res.status(204).end();
|
||||||
log.warn(log._("api.flows.error-save",{message:err.message}));
|
}).otherwise(function(err) {
|
||||||
log.warn(err.stack);
|
log.warn(log._("api.flows.error-reload",{message:err.message}));
|
||||||
res.status(500).json({error:"unexpected_error", message:err.message});
|
log.warn(err.stack);
|
||||||
});
|
res.status(500).json({error:"unexpected_error", message:err.message});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
redNodes.setFlows(flows,deploymentType).then(function() {
|
||||||
|
res.status(204).end();
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
log.warn(log._("api.flows.error-save",{message:err.message}));
|
||||||
|
log.warn(err.stack);
|
||||||
|
res.status(500).json({error:"unexpected_error", message:err.message});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ var log = require("../log");
|
|||||||
|
|
||||||
var promiseDir = nodeFn.lift(mkdirp);
|
var promiseDir = nodeFn.lift(mkdirp);
|
||||||
|
|
||||||
|
var initialFlowLoadComplete = false;
|
||||||
var settings;
|
var settings;
|
||||||
var flowsFile;
|
var flowsFile;
|
||||||
var flowsFullPath;
|
var flowsFullPath;
|
||||||
@ -191,8 +192,11 @@ var localfilesystem = {
|
|||||||
|
|
||||||
getFlows: function() {
|
getFlows: function() {
|
||||||
return when.promise(function(resolve) {
|
return when.promise(function(resolve) {
|
||||||
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
|
if (!initialFlowLoadComplete) {
|
||||||
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
|
initialFlowLoadComplete = true;
|
||||||
|
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
|
||||||
|
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
|
||||||
|
}
|
||||||
fs.readFile(flowsFullPath,'utf8',function(err,data) {
|
fs.readFile(flowsFullPath,'utf8',function(err,data) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
return resolve(JSON.parse(data));
|
return resolve(JSON.parse(data));
|
||||||
|
Loading…
Reference in New Issue
Block a user