【问题标题】:ReferenceError: For request with hapi/Node.jsReferenceError:对于 hapi/Node.js 的请求
【发布时间】:2015-07-06 19:22:01
【问题描述】:

我有这两个 api 处理程序:

module.exports.loginWeb = function (request, reply, next) {
    if (request.auth.isAuthenticated) {
        return reply.redirect('/');
    }

    if(request.method === 'get'){
        reply.view("account/login", { title: 'Login' },  {layout: 'account'});

    }else{
        console.log(request);
        login(request, reply, next, 'web');
    }
};

module.exports.registerWeb = function(request, reply, next) {
    if (request.auth.isAuthenticated) {
        return reply.redirect('/');
    }

    if(request.method === 'get'){
        reply.view("account/register", { title: 'Register' },  {layout: 'account'});
    }else{
        // checkbox1 name should be changed
        if (!request.payload.checkbox1){
            return reply('Please accept Terms & Conditions')
        }

        register(request, reply, next, 'web');
    }
};

注册处理程序工作正常,但登录处理程序出错,ReferenceError: Uncaught error: request is not defined.

但是请求被成功打印在该行的上方。可能是什么问题呢?同样正如我所说,注册处理程序可以使用相同类型的代码正常工作。

编辑:添加登录功能

function login(register, reply, next, flag){
    if (!request.payload.email || !request.payload.password){
        return reply('Please enter email and password');
    }
    Account.findOne({email: request.payload.email[0]}, function(err, user){
        if (err){
            return reply(err)
        }
        else {
            if (!user){
                return reply('user doesnt exists')
            }
            else {
                //doing bunch of stuff
            }
        }
    })
}

【问题讨论】:

  • login 长什么样子?

标签: javascript node.js hapijs


【解决方案1】:

问题出在 login 函数中 - request 未定义为此函数的参数。也许你的意思是写:

login(request, ...

你在哪里

login(register, ...

【讨论】:

  • 这是一个尴尬的错误。无论如何,非常感谢:)
猜你喜欢
  • 2018-04-04
  • 1970-01-01
  • 2017-12-23
  • 2018-03-01
  • 1970-01-01
  • 2018-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多