hapijs OnRequest服务器扩展不访问服务器插件

时间:2017-01-24 06:32:47

标签: node.js hapijs

i18n用于国际化目的。

当用户在网址上发送语言代码时,我会更改i18n的语言,如http://localhost:8080/signup?language=en 为此,我使用服务器扩展OnRequest。因此,每条路线都是全球性的, 但问题出现的是当我在OnRequest中访问i18n时,它显示未定义的错误 但是在路由处理程序中它显示了hapi-i18n的所有属性 这是我的代码和输出

server.ext('onRequest', function(request, response){
console.log("pre handler");
console.log(request.i18n);


return response.continue();
});

输出: 的未定义

但是在处理程序中

{
    method : 'POST',
    path   : "/signup",
    config : {
        tags        : ['api'],
        description : 'Customer signup',
    },
    handler: function(request, response){
        console.log(request.i18n);
    }
 }

输出:

{ __: [Function],
    __n: [Function],
   getLocale: [Function],
   setLocale: [Function],
   getCatalog: [Function],
   locale: 'en' 
}

1 个答案:

答案 0 :(得分:0)

您需要使用onPostAuth扩展点作为您使用的模块在请求对象生命周期中操作onPreAuth扩展点上的请求对象。

相关问题