Node.js:如何通过我的服务器将远程文件流式传输给用户?

KJW*_*KJW 2 download stream node.js

somwhere.com/noo.bin上有一个大型二进制文件

我想在我的网络应用程序上将此信息发送给用户.

我不想在我的服务器上保存这个文件然后提供服务,想知道是否有办法流式传输我的网络应用程序作为代理的文件(该文件看起来像mysite.com/noo.bin)

Lau*_*rin 8

安装请求,然后:

var http = require('http'),
    request = require('request'),
    remote = 'http://somewhere.com';

http.createServer(function (req, res) {
  // http://somewhere.com/noo.bin
  var remoteUrl = remote + req.url;
  request(remoteUrl).pipe(res);
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)