POST
簡単に言うと、リクエストがGET
Express 4に変換されるログイン ページがあります。
私のログインページのビジネス部分は次のとおりです。
<form id='loginForm' action='/login' method='post'>
<table>
<tr>
<td><input type='text' name='username' /></td>
</tr>
<tr>
<td><input type='text' name='password' /></td>
</tr>
<tr>
<td><button type='submit'>Submit</button></td>
</tr>
</table>
</form>
ここに私が設定したルートがあります:
// Express 4
var router = express.Router();
router.get('/login', function(req, res) {
res.render('./login.hbs', { message: req.flash('loginMessage') });
});
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/welcome',
failureRedirect: '/login',
failureFlash : true
}));
passport.use('local-login',
new LocalStrategy(
{
usernameField: 'email',
passwordField: 'password',
passReqToCallback : true
},
function(req, email, password, next) {
User.findOne({ 'authLocal.email' : email }, function(err, user) {
console.log('Inside local-login strategy with findOne A');
[snip]
ストラテジーのres.render
forGET /login
とfindOne()
call にブレークポイントを設定しました。local-login
「送信」ボタンをクリックすると、物事をキャッチするブレークポイントがrouter.get()
コード内にあります。
デバッガーでreq.method
は、 GET
.
ブラウザー (Chrome) で、302 を返す POST を実行していると言われます。コード 200/login
の保留中もあります。これらの 2 つのコード (302、200) は、デバッガーが で停止したときのものです。ブラウザのキャッシュをクリアしても効果はありません。GET
/login
router.get()
POST
私の要求が受け入れられない理由を教えてもらえますか?