sholladay / pogo

Server framework for Deno

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't send file over IP

jaspermolgvits opened this issue · comments

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.

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:

pogo/test/toolkit.js

Lines 88 to 104 in c4b0316

test('h.file()', async () => {
const server = pogo.server();
server.route({
method : 'GET',
path : '/names',
handler(request, h) {
return h.file('./test/fixture/names.json');
}
});
const response = await server.inject({
method : 'GET',
url : '/names'
});
assertStrictEquals(response.status, 200);
assertStrictEquals(response.headers.get('content-type'), 'application/json; charset=utf-8');
assertEquals(response.body, new TextEncoder().encode('[\n "Alice",\n "Bob",\n "Cara"\n]\n'));
});

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.

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.

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.

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.

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