Can't post or patch records using nodejs


#1

Using DreamFactory 2.14 (Bitnami image, EC2)
I had to upgrade the supplied nodejs from version 6 to the latest stable (version 10) to get a response from platform.api.get. But platform.api.post is still broken, as is platform.api.patch.
Like other users, I’m getting the feeling we’re on a sinking platform here, with bugs like this and with the silence in this forum.

More info:
which node
/opt/bitnami/nodejs/bin/node
node -v
v10.14.1

platform.api.post result: No record(s) detected.
A V8js pre-processing script on the table being posted to shows that event.payload is indeed empty.

platform.api.patch result: The request contains no valid record fields.

Sample code to reproduce:

options = {
‘headers’: {
‘X-DreamFactory-Api-Key’: platform.session.api_key,
‘X-DreamFactory-Session-Token’: platform.session.session_token,
‘Content-Type’: ‘application/json’
}
};

url = ‘http://localhost/api/v2/db/_table/table_name/’ + 1;

payload = {“field”: “value”};
platform.api.patch(url, payload, options, function(body, response) {
result = JSON.parse(body);
if (!result) {
console.log(body);
} else if (result.error) {
console.log(result.error.message);
} else {
console.log(‘internal URL updated 1 record’);
}
});


#2

Hi @jps

I saw that you ran the which node command, and it brought back the correct nodejs path. Did you change your .env file to reflect the correct path?

CloudApp

Also you point out that you used a v8js script to test, but could you please try a node script as well? These are not the same engine and are not sourced via the same scripting paths.

Thanks!


#3

Hi,

Regarding the path to node:
cat /opt/bitnami/apps/dreamfactory/htdocs/.env | grep NODE
DF_NODEJS_PATH=/opt/bitnami/nodejs/bin/node

which node
/opt/bitnami/nodejs/bin/node
They’re the same.

Regarding V8js: I think there is a misunderstanding here. We’re talking about two different tables, each with a script attached (pre-processing).

  • Table A has a nodejs preprocessing script, needed because of some special functionality for AWS that is not available in V8js. This is the only nodejs script in my solution. There are several problems with nodejs in DreamFactory, which is why I avoid it. Table A is posted to by the client software. The result should be something in AWS, a new record in table A and a patched record in table B.

  • The nodejs script attached to table A patches (or tries to patch) a record in table B as part of its preprocessing. The result is always : “The request contains no valid records”.

  • I put a V8js preprocessing script on table B to find out what is sent there by nodejs preprocessing from table A, for debugging purposes only. That script shows that the payload indeed arrives there empty.

In short, I have not been able to PATCH or POST records successfully from nodejs v10. The original nodejs supplied in the Bitnami image is v6, that one does not do GET either (platform.api.xxx starts and returns nothing), v10 at least manages GET, but not POST or PATCH.


#4

Aha, thanks for the clarification, @jps. Looking into this further now. Thanks for confirming your Node path as well.