处理express.js中的POST请求时出错404

时间:2016-01-25 18:47:47

标签: javascript node.js express

js和express,下面是路由处理程序文件:

var express = require('express');
var passport = require('passport');
var authRoutes = App.route('authRoutes');
var sessionRoutes = App.route('sessionRoutes');
var userRoutes = App.route('userRoutes');


var invalidUserError = App.middleware('invalidUserError');
var validateNewUser = App.middleware('validateNewUser');


function AuthRoutes(app){
    var Authrouter = express.Router();
    Authrouter.route('/signIn')
        .get(authRoutes.signIn)
        .post(validateNewUser, userRoutes.create,invalidUserError);

    Authrouter.route('/signUp')
        .get(authRoutes.signUp)
        .post(passport.authenticate(
            'local', 
             { successRedirect : '/portal' },        
             { failureRedirect : '/auth/signIn' }
        ));

    app.use('/auth',Authrouter);
}
module.exports = AuthRoutes;

我能够正确处理获取请求但是当我对/ signIn网址发出POST请求时,我收到了404找不到的响应,请帮忙。

1 个答案:

答案 0 :(得分:1)

您在网址中需要的路径是/auth/signIn,因为您使用Authrouter前缀加载了/auth