lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

support binding to a given address only #57

Closed christophgysin closed 7 years ago

christophgysin commented 7 years ago

Also, defaults to listening on localhost by default. Set --address 0.0.0.0 to listen on all interfaces.

fixes #55

christophgysin commented 7 years ago

The failing check seems to fail on master too: https://travis-ci.org/75lb/local-web-server/branches

75lb commented 7 years ago

Hi, thanks for this PR - it highlighted that local-web-server was suddenly broken in node v4 and v5 thanks to misuse of semver in the Koa project.

Thanks for the new feature - I started looking at it but have run out of time, for now. Will look again tonight. The first issues i noticed were lack of basic validation:

$ ws -a
serving at http://null:8000
$ ws -a server.home
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND server.home
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)

Will look more later.

christophgysin commented 7 years ago

I confess that I have not done much input validation.

$ ws -a serving at http://null:8000

This seems like something the command line parser should handle. Is there a way to mark the argument to -a as required?

$ ws -a server.home events.js:163 throw er; // Unhandled 'error' event ^

Error: getaddrinfo ENOTFOUND server.home at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)

While verification for this can be implemented, it requires a DNS lookup. Maybe it would be better to only allow IP addresses. They can easily be validated. Is there a real use-case for listening on a hostname? It's usually either 127.0.0.1 or 0.0.0.0, or then a specific IP address assigned to a local interface.

75lb commented 7 years ago

don't worry, I will see to this feature. I working on version 2 of local-web-server as we speak, it is long overdue. I'll let you know once it's in beta!