hellriser
hellriser

Reputation: 27

Connect app engine with ibm cloudant using XMLHttpRequest

I am using a standard app engine configuration in Node.js. I am having trouble accessing ibm cloudant from app engine using the xmlhttprequest.

The code i am using for the request from App engine is as follows:

var getAllDocuments = function(database, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", false);
    xhr.setRequestHeader("Authorization", myauthenticateUser(userName, passWord));
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function (){
        if (xhr.readyState == 4 && xhr.status == 200) {
         var data = JSON.parse(xhr.responseText);
         callback(data, xhr.status);
        }
        else{
            callback(null, xhr.status);
        }
    }
    xhr.send();
} 

when the above code is executed the following error happens-: Error: EROFS: read-only file system, open '.node-xmlhttprequest-sync-11 '.

FYI: I am not saving any temp file in my app engine.

Is there something to be added to the yaml file that i created or is this something else?

Upvotes: 0

Views: 81

Answers (1)

Joss Baron
Joss Baron

Reputation: 1524

The error seems self-explanatory:

Error: EROFS: read-only file system, open .node-xmlhttprequest-sync-11

Those files are genetared due to the usage of syncronous requests. Please take a look into this similar question where they launch "nodemon" it keeps creating files .node-xmlhttprequest-sync-1516 (random numbers in the end).

Additionally, according to this I found that:

Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), Blink 39.0, and Edge 13, synchronous requests on the main thread have been deprecated due to their negative impact on the user experience.

Synchronous XHR is now in deprecation state.

So, you might think to restructure your code to use async instead.

I wanted to search more and I found this entry in github issues

Generally, if you're getting these files, it means you're using synchronous http requests, which is a no no. You shouldn't do that, for this effects and other reasons. Please check your code for synchronous requests and remove them.

If you see Truffle code that uses synchronous requests, please let us know.

And I think this responds to your question:

Just FYI, this file isn't truffle generated. It comes as a result of using synchronous http requests in node.

SOLUTION: change to asynchronous request. For that you have to change this line

xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", false);

for this:

xhr.open("GET","<link>" + database + "/_all_docs?include_docs=true", true);

Changing the flag false to true. For more details take a look into this

Upvotes: 1

Related Questions