let post =
{
method: 'POST',
path: '/posts/new/{postType}',
handler: (request, reply) =>{
//when params is text
if (request.params.postType == "text")
{
return reply("successfully uploaded text post");
}
//when params is image
else (request.params.postType == "image")
{
//call proxy uri to save the image
/*proxy:
{
uri: proxyUri + '/post/image', //call proxy uri to save the image
passThrough: true,
acceptEncoding: false,
}*/
}
}
如何基于路由参数有条件地调用代理服务器,因此我使用一个休息api来发布文本,图像,视频等?
答案 0 :(得分:1)
您可以使用reply.proxy()。
const route = {
/* ... */
handler: (request, reply) => {
if (request.params.useproxy) {
return reply.proxy({host: 'example.com', port: 80, protocol: 'http'});
} else {
return reply('no proxy');
}
}
};