我想在Hapi.js中對我的路線實施X-Authorization。因此,當我提出請求時,我將創建一個X-Auth頭文件,並且希望Hapi在允許執行一些代碼之前對其進行檢查:Hapi.js - 設置X-Authorization標頭
基於Hapi documentaiton的這個代碼示例,我該如何實現它?
server.route({
method: 'GET',
path: '/hello/{user?}',
handler: function (request, reply) {
const user = request.params.user ? encodeURIComponent(request.params.user) : 'stranger';
reply('Hello ' + user + '!');
},
config: {
description: 'Say hello!',
notes: 'The user parameter defaults to \'stranger\' if unspecified',
tags: ['api', 'greeting']
}
});