I'm looking for an option to be able to disable/enable the editor on the fly so I thought about calling editor.stop() in a function node when I want to disable the editor (and later editor.start() to enable it). However, when stopping the editor, node-red crashes immediately. It might have to do something with the fact that I'm also communicating with node-red from the app via the http api but I thought that the editor and the runtime are separated. Besides that it does crash immediately so I don't think that any http api calls are involved.
That's what I get in the terminal:
4 Sep 16:04:36 - [warn] Communication send error: Error: WebSocket is not open: readyState 3 (CLOSED)
4 Sep 16:04:37 - [red] Uncaught Exception:
4 Sep 16:04:37 - TypeError: Cannot read property 'handleUpgrade' of null
at Server.upgrade (/usr/local/lib/node_modules/node-red/node_modules/@node-red/editor-api/lib/editor/comms.js:204:30)
at Server.emit (events.js:323:22)
at onParserExecuteCommon (_http_server.js:642:14)
at onParserExecute (_http_server.js:583:3)
I simply required @node-red/editor-api in the functionGlobalContext section in settings.js, retrieved a reference to it in a variable (say editor) via global.get() as it is usually done in such cases and called editor.stop().
That is not possible to do. You cannot freely start and stop the editor - the API is not designed to support that.
Whether it could be possible is a separate question - but would require some amount of development work to support. It is not a bug as it is not a feature offered by the module.
As for the uncaught exception you've hit - there is something to look at there, but given this path is only hit when Node-RED is shutting down, it isn't too concerning.
Okay, understood. The question is then if it's possible in any other way? Afaik, disableEditor cannot be turned on/off on the fly. I also thought about disabling it via http api authorization but currently it's either * or read and there's no option to block access to the editor only and let http api access open.
Do you happen to have any hint how to get it done?
Managed to control it via req.originalUrl but if I'd like to peek in the request body it's just undefined as if there was no bodyparser in place. Is that the case? If so, what can I do about it?
I know I already asked it but I couldn't solve this since then Do you happen to have any hint for this?
"Managed to control it via req.originalUrl but if I'd like to peek in the request body it's just undefined as if there was no bodyparser in place. Is that the case? If so, what can I do about it?"