sholladay / pogo

Server framework for Deno
Mozilla Public License 2.0
482 stars 33 forks source link

Can't send file over IP #60

Closed jaspermolgvits closed 3 years ago

jaspermolgvits commented 3 years ago

Hi, Can someone please confirm that pogo works with the latest version of deno? I've been trying out deno's built in http, oak and abc and haven't had problems, but pogo won't even work over ipv4, only localhost for some reason. On localhost return 'Hello, world!'; works correctly, but return h.file('index.html'); gives {"error":"Internal Server Error","message":"Internal Server Error","status":500} on the browser. There are no errors on the server console.

sholladay commented 3 years ago

Hi, @jaspermolgvits! I think you're running into Deno's security features. Are you passing --allow-read to allow Pogo to access the filesystem? It definitely works. That said, I just noticed the documentation only explicitly mentions --allow-read in one place, and it's probably hard to notice at a glance. A PR to improve the documentation would be much appreciated if you have time.

Here are the relevant tests: https://github.com/sholladay/pogo/blob/c4b0316131b6650fc7acfe9534afb69d1a664516/test/toolkit.js#L88-L104

jaspermolgvits commented 3 years ago

Thank you for your reply. --allow-read did indeed allow me to send files... I forgot I wasn't running -A and I should've realized as much. However, connecting to my ipv4 (http://192.168.0.182:3000/) still doesn't give a response.

sholladay commented 3 years ago

That's another security feature, but this time one that is part of Pogo, as opposed to --allow-read which is a Deno thing.

Unlike other frameworks, by default Pogo only listens for requests from your machine. To explicitly opt-in to listening for requests from external machines, set the server hostname option. For example, server({ hostname : '0.0.0.0' }) will listen on all addresses. There is some documentation about it here: https://github.com/sholladay/pogo/blob/master/docs/security.md

Should probably add a link to that in the API docs for server.start() and maybe other places.

jaspermolgvits commented 3 years ago

Yep, that did the trick! You've been very helpful, but if you don't mind I need just one more tip in regards to networking with Deno...

Having just migrated from Node/Express to Deno, I've been looking for a server framework that allows seeking/scrubbing in HTML audio/video files. Express does this by default, but none of the frameworks on Deno do, Pogo included. They're just fixed to playing from start to end? I feel like I'm missing something obvious.

const stream = await Deno.open('test.mp4'); return h.response(stream).type('video/mp4'); crashes the server with ConnectionAborted: An established connection was aborted by the software in your host machine. (os error 10053) And const buffer = await Deno.readFile('test.mp4'); return h.response(buffer).type('video/mp4'); doesn't have any effect.

sholladay commented 3 years ago

Hmm, that's strange. I'll try to reproduce that. In general, I would strongly recommend that you host large media files on Amazon S3 (or similar) and then have the client load them directly from S3. That's the recommended practice for Node.js, too.

That said, we should totally be able to make this work. I have a hunch that as you're scrubbing, the browser is attempting to make HTTP Range requests even though Pogo doesn't return an Accept-Ranges header, and that this is somehow crashing the server. Would be great to add automatic range handling to Pogo, regardless, and it should be doable by using Deno.seek() on the file returned by the route handler. I won't be able to look into this right away, so I'd suggest starting there if you want to debug it.

jaspermolgvits commented 3 years ago

Many thanks, @sholladay! I'll look into Deno.seek().