Step 1: Identify current state
node-red
before starting anything
22 Jun 16:39:41 - [info] Node-RED version: v2.2.2
22 Jun 16:39:41 - [info] Node.js version: v12.22.12
22 Jun 16:39:41 - [info] Linux 5.13.0-1031-aws x64 LE
22 Jun 16:39:41 - [info] Loading palette nodes
22 Jun 16:39:42 - [info] Settings file : /home/ubuntu/.node-red/settings.js
22 Jun 16:39:42 - [info] Context store : 'default' [module=memory]
22 Jun 16:39:42 - [info] User directory : /home/ubuntu/.node-red
22 Jun 16:39:42 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Jun 16:39:42 - [info] Flows file : /home/ubuntu/.node-red/flows.json
22 Jun 16:39:42 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
22 Jun 16:39:42 - [error] Unable to listen on http://127.0.0.1:1880/
22 Jun 16:39:42 - [error] Error: port in use
Note I am not using the default port
Step 2: Enable httpNodeMiddleware
httpNodeMiddleware: function(req,res,next) {
// // Handle/reject the request, or pass it on to the http in node by calling next();
// // Optionally skip our rawBodyParser by setting this to true;
req.skipRawBodyParser = true;
next();
},
...restart node red pm2 restart node-red
node-red
provides same result
Running a flow with http in... input still parsed object
in settings.js, just enabled the
httpAdminRoot: '/admin',
... restart node red pm2 restart node-red
and check node-red
The terminal output is now different
22 Jun 16:51:47 - [info] Node-RED version: v2.2.2
22 Jun 16:51:47 - [info] Node.js version: v12.22.12
22 Jun 16:51:47 - [info] Linux 5.13.0-1031-aws x64 LE
22 Jun 16:51:48 - [info] Loading palette nodes
22 Jun 16:51:48 - [info] Settings file : /home/ubuntu/.node-red/settings.js
22 Jun 16:51:48 - [info] Context store : 'default' [module=memory]
22 Jun 16:51:48 - [info] User directory : /home/ubuntu/.node-red
22 Jun 16:51:48 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Jun 16:51:48 - [info] Flows file : /home/ubuntu/.node-red/flows.json
22 Jun 16:51:48 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
22 Jun 16:51:48 - [error] Unable to listen on http://127.0.0.1:1880/admin/
22 Jun 16:51:48 - [error] Error: port in use
Catching a new webhook... msg.payload is again an object
After changing the root directory, I also get a 404 error from Postman. The error is due to cryptojs library I manually added in node red. I assume the library cannot be accessed from the /admin directory
Step 4: Try the adding the code
Coded Added
var bodyParser = require('body-parser');
var jsonParserWithRawBody = bodyParser.json({
verify: function (req, res, buf, encoding) {
req.rawBody = buf;
}
})
in the very beginning - just above module.exports
Coded removed
Commented out the httpNodeMiddleware that I enabled in Step 2 and added the code above instead
httpNodeMiddleware: function(req,res,next) {
if (req.url === '/my/httpin/url/where/i/want/to/have/the/raw/body') {
jsonParserWithRawBody(req, res, next);
} else
next();
},
...restart ... node-red
Error loading settings file: /home/ubuntu/.node-red/settings.js
ubuntu@ip-172-31-32-243:~$
Nothing works, I am exhausted