0

I have videos stored on a server (server1) that some clients have no access to, and I have another server (server2) that has access to server1 and the clients have access to.

I want those clients to be able to watch those videos through server2 on their browsers.

  • I can't just redirect them to server1 cuz they can't access it.
  • I can't download and save the videos on server2 cuz I don't have that much of space on it.
  • I know how to stream a local video to a client using chunks.
  • I know how to download and save a video using http.

Is there any way I can stream those videos from server1 to the clients using nodejs on server2?

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

0

The request module is deprecated but they have a nice streaming example

const request = require('request');

http.createServer(function (req, resp) {
  if (req.url === '/doodle.png') {
    if (req.method === 'GET') {
      request.get('http://example.com/doodle.png').pipe(resp)
    }
  }
})

You can use the request module, it's still rock, or to adapt to any other request alternative or the built in http module.

yeya
  • 1,968
  • 1
  • 21
  • 31
  • I used request module for that and it didn't help me alot because the size of each video is kind of large (around 2 GB) so request module didn't pipe the whole video, it only like the first 10 MB of it. And I also couldn't stream the video in chunks with request. – Hani Fedler Jun 09 '21 at 08:52
  • Probably not request issue, probably server issue or proper headers for client. When request \nodejs stream, no one really care about the size. – yeya Jun 09 '21 at 08:55
  • BTW, do you have to solve it specifically by NodeJS server? It can easily solved by a well configured proxy – yeya Jun 09 '21 at 08:57
  • I used request to pipe a 2 minute video with about 30 mb size and worked just fine. But with 1hr video with 1gb size it gave me just the first 3 minutes of it. I think the problem in in the size of the response that request can get and pipe. – Hani Fedler Jun 09 '21 at 09:27
  • is there an article or something you can provide me about the proxy thing? – Hani Fedler Jun 09 '21 at 09:29
  • It's usually referred as 'reverse proxy', I need more info on the infrastructure to suggest specific solution. – yeya Jun 09 '21 at 09:43
  • https://www.nginx.com/resources/glossary/reverse-proxy-server/ – yeya Jun 11 '21 at 10:18
  • OK, so I got the concept of the proxy server. But how do I fix my problem using nodejs. – Hani Fedler Jun 15 '21 at 12:36
  • I don't know what cause the request to stop so I can't help you. Try with different file servers to eliminate server issues. – yeya Jun 15 '21 at 12:42