每当有人点击/data
路线时,我都会触发一个功能。我想用一个无头浏览器实例自己来点击它。或者我的思维过程只是出去吃午饭?
nightmare.goto('http://localhost:3000/data')
.then(() => {
console.log('did it work?');
})
app.get('/data', (req, res) => {
myfunction();
})
获取: UnhandledPromiseRejectionWarning:错误:导航错误 很明显它并不是那样的。有什么想法吗?
答案 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.