プロジェクトで作業していて、データベースにスキーマを作成した後に.then関数を使用する必要がありますが、何らかの理由でres.render
関数.then()関数では、ページが読み込まれません。それは私のアプリがポートで実行されていると私のデータベースに接続されていると、すべてがうまくいくようだ。私はすべてが定義され、それが私のコードでエラーが表示されないされ .then関数を使用しているときにページが読み込まれない
function getVenues (bars){
bars.map((eachBar) => {
Venue.findOne({
id: eachBar.id,
title: eachBar.name,
image: eachBar.image_url,
url: eachBar.url,
rating: eachBar.rating
}, (err, venue) => {
if(err) return (err);
if(!venue){
var newVenue = new Venue({
id: eachBar.id,
title: eachBar.name,
image: eachBar.image_url,
rating: eachBar.rating,
url: eachBar.url
}).save((err, venue) => {
if(err) return err;
})
}
})
})
}
router.get('/', function (req, res) {
res.header('Access-Control-Allow-Credentials', true);
request.get('http://ipinfo.io/' + req.headers['x-forwarded-for'], {json: true}, function (e, r){
client.search({
term: "bars",
latitude:r.body.loc.split(",")[0],
longitude: r.body.loc.split(",")[1]
}).then(response => {
getVenues(response.jsonBody.businesses).then(function(results){
res.render('home', {
bars: results,
term: 'Bars near you',
authenticated: req.isAuthenticated()
});
console.log(results);
});
console.log(req.isAuthenticated());
});
});
});
をcloud9を使用して、ここでindex.jsファイルのための私のコードです
ています。ここで問題となるのは、関数を.then関数の外に置くと、それは完全にうまく動作し、すべてがロードされますが、今はロードを続けて、クラウド9サイトのError 502 - Bad Gateway
というエラーになります。誰がなぜそれが起こり、それを解決する方法を知っていますか?
:(あなたがthensのカスケードを持っている - - 一般的な場合または最後
then
)、あなたはどのエラーが発生見るべきちょうど各then
の閉じ括弧の後にcatch
を追加あなたのAPIにアクセスする際にエラーが発生したときにトリガー – darham