gpt4 book ai didi

node.js - 如何将 url 查询参数添加到 hapijs 中的 hapi 代理调用中

转载 作者:太空宇宙 更新时间:2023-11-03 23:09:19 25 4
gpt4 key购买 nike

假设我想在这次对 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com