簡體   English   中英

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

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

我正在尋找hapi中的parllel方法

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

如何在hapi中管理響應?

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


    //????reply(?);



}
});  

從另一個問題/答案:

function (request, reply) {

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

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

如果您只需要轉發上游響應,則可以通過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