我可以指示nightmare.js去localhost的快速路线吗?

时间:2018-06-02 02:39:54

标签: node.js express nightmare

每当有人点击/data路线时,我都会触发一个功能。我想用一个无头浏览器实例自己来点击它。或者我的思维过程只是出去吃午饭?

nightmare.goto('http://localhost:3000/data')
.then(() => {
  console.log('did it work?');
})


app.get('/data', (req, res) => {
  myfunction();
})

获取: UnhandledPromiseRejectionWarning:错误:导航错误 很明显它并不是那样的。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

You need to create the server before you try to reach it from nightmareJS. So,

app.listen(3000, function(){
  nightmare.goto('http://localhost:3000/data')
  .then(() => {
    console.log('did it work?');
  })
})

Really bad example, but that's what you are looking for. Hope it works.