次のような単純な Ajax リクエストがあります。
$.ajax({
type: "POST",
url: "/admin.html",
data: dataString,
success: function(data) {
if(data.error) {
$('#alertt').text(data.error);
$('#alertt').show();
$('#alertt').fadeIn().delay(2000).fadeOut('slow');
} else if (data.success) {
var lati = $('#route_latitude').val();
var longi = $('#route_longitude').val();
increment();
setMarker(lati, longi);
$('#alertt').text(data.success);
$('#alertt').show();
$('#alertt').fadeIn().delay(2000).fadeOut('slow');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus + " " + errorThrown)
}
})
問題は、ユーザーが Web ページにサインインしている場合、(pending)
約 5 分間待機してからエラーが発生することです。これがなぜなのかわかり500
ません。Express v3
var isAdmin = function(req, res, next) {
helper.isAdmin(req, res, next);
}
app.post('/admin.html', isAdmin, admin.new);
exports.isAdmin = function(req, res, next) {
db.users.find({'rememberToken': req.cookies.rememberToken}, function(err, foundUser) {
if (err) { console.log('We have an error' + err) } else {
if (foundUser.length === 0) {
console.log('Somebody attempted to view the Admin page without an account.')
res.render('index', { 'title': 'Home Page'})
} else if (foundUser[0].admin === 0) {
console.log('A non-admin user account tried to log into the Admin page: ' + foundUser[0].email);
res.render('index', { 'title': 'Home Page' });
} else if (foundUser[0].rememberToken === req.cookies.rememberToken) {
console.log('Admin viewing Admin page.');
next();
}
}
})
}
本当に何も問題はありませんが、何らかの理由でただ座っているだけ(pending)
ですが、Cookieを設定せずにログインしないと(isAdmin function
から削除された状態でpost
)動作します。どんな助けでも素晴らしいでしょう、これは私を夢中にさせています。
サインインの処理方法に興味がある場合: https://gist.github.com/anonymous/f458783ffdc45255f85d/raw/dd59d045b7fa76abc2dca458eea16702477c36d1/gistfile1.js
これは実際にはlocalhostでは意図したとおりに完全に機能しますが、Nodejitsuにプッシュすると機能せず、この問題が発生します。