I am trying to create a PDF file from a dynamic helm web page that will display data from a database. As soon as I get this to work on my local machine, I would like to move the code to an elastic beanstalk. It seems that the code is starting, which initially makes a call to appear, but the call to phantomjs does not seem to run the script passed to it. To confirm this, I added the console.log statement at the very beginning of the file and never printed it. Not to mention another print statement in the script file. Code below:
code that performs the spawn: var childArgs = [ //'--debug=true', path.join(__dirname, '../phantom/capture.js'), id, filename ]; let child = spawn(phantomjs.path, childArgs, {detached: false}); console.log('set up stderr.....'); child.stderr.on('data', (data) => { console.log('ps stderr: ${data}'); }); console.log('set up stdout.....'); child.stdout.on('data', (data) => { console.log('ps stdout: ${data}'); }); console.log('set up close.....'); child.on('close', (code) => { console.log('this is a test 2.....'); console.log(code); if (code !== 0){ let error = new Error('An error occurred while creating the current report.'); error.status = 500; reject(error); } resolve(fname); return; }); capture.js: console.log('we are inside....'); let os = require('os'); var system = require('system'); console.log('we are inside.... 1'); var page = require('webpage').create(); let phantom = require('phantomjs-prebuilt'); console.log('we are inside....2'); var args = system.args; console.log('we are inside....3'); if (args.length === 1) { phantom.exit(0); } else { page.viewportSize = { width: 2000, height: 800 }; //page.paperSize = { format: 'Letter', orientation: 'landscape', margin: '1cm' }; page.paperSize = { width: '1280px', height: '800px', margin: '0px' }; page.settings.localToRemoteUrlAccessEnabled = true; page.settings.loadImages = true; page.settings.javascriptEnabled = true; let done = false; //"http://example.com/order/" + args[1] + '?token=' + args[2] page.open("http://example.com/order/" + args[1], function start(status) { if (status === "success"){ page.render(os.tmpdir() + '/' + args[2], { format: 'pdf' }); } done = true; }); var intervalId = setInterval(function(){ if (done){ phantom.exit(); } }, 100); }
I am at a loss where the problem may be. It seems that the first line of capture.js is not called. 1) What is the problem that I am missing? 2) How can I fix this?
source share