lukeed / sirv

An optimized middleware & CLI application for serving static files~!
MIT License
1.07k stars 58 forks source link

Add option to bind host to 0.0.0.0 #29

Closed LySofDev closed 5 years ago

LySofDev commented 5 years ago

Hello Luke,

I wanted to try out the Svelte project which uses the sirv-cli as development server. I generally run my development environments from within Docker containers which require that a server bind to host 0.0.0.0. Otherwise, my browser is unable to connect to the development server.

I tried using the --cors option to get past this issue but it didn't work. Am I perhaps missing something? Is it possible to bind your current implementation with an undocumented option?

Unfortunately, I had to switch over to a different development server but would like to use the recommend one.

Thank you for your time and awesome package.

LySofDev commented 5 years ago

Unless you have a reason not too, you could probably add the option and pass the host as the second argument to the server.listen call.

https://github.com/lukeed/sirv/blob/11cc39a95eecf8fa59627b4bde9c81b595f8648b/packages/sirv-cli/boot.js#L61

Node docs indicate that the second optional argument is the host.

https://nodejs.org/api/net.html#net_server_listen

lukeed commented 5 years ago

Yes, for sure! I thought it was in there already but guess not.

I'll get it in tonight unless you want to beat me to it. Currently away from my computer - back soon

lukeed commented 5 years ago

Hey, thanks

So I took care of --host, -H support. While I was at it, I added support for HOST and PORT environment variables, which also should have been there.

These options are now available in sirv-cli@0.4.3:

$ PORT=3000 sirv public
$ HOST=0.0.0.0 sirv public
$ sirv public --host 10.0.0.1
LySofDev commented 5 years ago

Thanks! :+1: