私は1ページのアプリケーションの正しい共有ページにphantomjsをphridgeで使用しています。Promise with res.send();
if (isbot(req.headers['user-agent'])){
var url= req.protocol+'://'+req.get('host')+ req.originalUrl
phridge.spawn()
.then(function (phantom) {
var page = phantom.createPage();
return page.run(url, function (url, resolve, reject) {
var page = this;
page.open(url, function (status) {
// handle page after load
});
})
.then(function (contnt) {
res.send(contnt);
})
.then(phridge.disposeAll());
.catch(function (err) {
console.error(err.stack);
})
}
else {
next();
}
の質問です - どのように約束して動作しますres.send()
メカニック: はここにいくつかのコード例ですか? phridge.disposeAll()
が実行されますか?
この行は間違っています - '.then(phridge.disposeAll());' 'phridge.disposeAll()'は関数を返しますか? '.then'への引数は関数でなければならないかもしれません。おそらく' .then(phridge.disposeAll); ' –
' phridge.disposeAll() 'が実行されます。 'res.send()'は同期関数と同じように動作します –