简体   繁体   English

如何在hapi.js中管道流回复

[英]How to pipe stream to reply in hapi.js

Im looking for the parllel method in hapi 我正在寻找hapi中的parllel方法

// Express + Request exmaple
function(req, res){
  request('http://example.com/image.png').pipe(res);
}

How to pipe a response in hapi ? 如何在hapi中管理响应?

server.route({
method:  "*",
path:    "/api/results/{date}",
handler: (request, reply) => {


    //????reply(?);



}
});  

From another question/answer: 从另一个问题/答案:

function (request, reply) {

    Request('http://example.com/image.png')
    .on('response', function (response) {
        reply(response);
     });
}

https://stackoverflow.com/a/31222563/2573244 https://stackoverflow.com/a/31222563/2573244

If you only need to forward an upstream response, you can just use a proxy handler via the h2o2 plugin: 如果您只需要转发上游响应,则可以通过h2o2插件使用代理处理程序:

server.route({
    method: 'GET',
    path: '/upstream/file',
    handler: {
        proxy: {
            uri: 'http://example.com/image.png'
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM