Tuesday, 4 April 2017

phantomjs create inside express Router does not execute

I have a server with routes built with express.Router. One of the routes uses phantom.create() inside. I can't get inside the create function, it never executes (or it does but without any effect). I run this script by node ./path/to/script :

var express = require("express");
var router  = express.Router();

router.post("/my/path", function(req, res) {
  console.log('req.body.myUrl', req.body.myUrl); // this works

  var phantom = require('phantom');
  phantom.create('--debug=true', '--web-security=false', function(ph) {
    // this never happens:
    console.log('phantom');
    return res.status(200).send({ message: "asdasd" });
  });

  console.log('mamma mia') // this works
});

The server logs this:

req.body.myUrl http://myUrl
mamma mia
# and after a few minutes this:
POST /screencapture/capture - - ms - -
# and then the entire cycle repeats infinitely automatically:
req.body.myUrl http://myUrl
mamma mia
POST /screencapture/capture - - ms - -

When I run the same code in a live node session ($ node), everything works just fine. Any idea what's the issue here? I've was digging in the create() source, but couldn't find any trail there :/

node v6.2.0, express 4.1.0, phantomjs 2.1.1, macOS Sierra 10.12.4,



via medik

No comments:

Post a Comment