假设我想在这次对 google 的调用中添加一个查询参数,但对其进行编码,而不是从 http 调用进行转发
我正在使用nodejs hapi框架
server.route({
method: '*',
path: '/{p*}',
handler: {
proxy: { host: 'google.com', port: 80, redirects: 5 }
}
});
可以在调用之前修改 url。
最佳答案
我通过代理做到了这一点:mapUri
server.route({
method: 'GET',
path: '/index/search/{p}',
handler: {
proxy: {
mapUri: function (request, callback) {
query = request.url.search ? request.url.search : '';
p = request.params.p ? '.' + request.params.p +'.' : '' ;
//loaded from a configuration file
tls = Config..tls;
host = Config..host;
port = Config.port;
url = (tls ? 'https://' : 'http://') + host + port + p + request.path + query;
console.log('Method: ' + request.method.toUpperCase() + ' Url: ' + url);
callback(null,url);
}
}
}
});
关于node.js - 如何将 url 查询参数添加到 hapijs 中的 hapi 代理调用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21745360/