I want to create a new topic after updating this topic since it is an old one and may be not related to my problem.
I have an external script that creates an XMPP user for CPEs:
"use strict"
const http = require("http");
let cache = null;
let cacheExpire = 0;
function addUser(args, callback) {
if (Date.now() < cacheExpire) return callback(null, cache);
var test = JSON.stringify({
"user": args[0];
"host": "localhost";
"password": args[1];
});
const options = {
hostname: '127.0.0.1',
path: '/api/register',
port: 5281,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': test.length
},
body: test };
const req = http.request(options, (res) => {
var chunks = [];
if (res.statusCode !== 200) {
return callback(null, null);
}
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
var result = JSON.parse(body.toString());
callback(null, result);
});
});
req.on("error", function (error) {
callback(error);
});
req.write(test);
req.end();
}
exports.addUser = addUser;
And this is called in provision:
const res = ext("ext-config", "addUser", "username","password");
But sometimes I have wrong arguments in my script such as the password is “(s,c)=>{e.delete(t[0])&&process.send([t[0],n(s),c])}” as in the screenshot.
My suggestion is to JSON encode all the data passed into the external script, then JSON.parse it in the script to extract out what you need. The big advantage of this is you are not tied to ordinal positioning for parameter values. This will reduce the cognative load when you have to look at the ext script in a years time.