I am in the process of creating a web API on port 7788 that will accept JSON data. This JSON data will then be passed to my API which will render a website. Next, PhantomJS will search for an element on that page and the web API on port 7788 should return that element. Everything is working smoothly until I encounter an error when trying to send a response to my server on port 7788:
Error: cannot access member `write' of deleted QObject.
The issue arises with this line of code: firstResponse.write(imgsrc);
I am wondering if it is possible to return an element within the response of the server.listen function after calling page.open?
var server = require('webserver').create();
var port = require('system').env.PORT || 7788;
server.listen(port, {'keepAlive': false}, function (request, response) {
console.log("request method: ", request.method); // request.method POST or GET
var imgsrc;
var firstResponse = response;
if (request.method == 'POST') {
var page = require('webpage').create();
var settings = {
operation: "POST",
encoding: "utf8",
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify(request.post)
};
var url = "http://127.0.0.1:5000/mapapp";
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.open(url, settings, function (status) {
setTimeout(function () {
page.evaluate(function () {
imgsrc = document.getElementById("exportedImg").src;
});
}, 5000);
});
page.close();
setTimeout(function () {
firstResponse.write(imgsrc);
}, 7000);
firstResponse.close();
}
});