lukeed / sirv

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

Please allow setting the network and the local address simultaneously #123

Closed tbenko73 closed 3 years ago

tbenko73 commented 3 years ago

Please allow the use of Local: localhost alongside with custom Network: address. If iI set a custom network address, ie:192.168.0.10 the Local address automatically changes to 0.0.0.0, and I cannot find a way to control the local address and the network address at the same time. Is this possible somehow?

lukeed commented 3 years ago

As soon as something is accessible over the network, it's definitionally no longer "localhost" -- you can still type in localhost to visit the site, but it has to be opened up on 0.0.0.0 in order for other network members to locate your address.

The only way "around this' is to run two servers, where one is private and the other is exposed to the network...but that still forces you to be 0.0.0.0 anyway & then you have to deal with separate ports. Aka, this is no workaround, this is just how it works

tbenko73 commented 3 years ago

I really understand your point, and I know that as soon something is accessible over network is no longer local. But that still leaves me with an unsolved problem. I really need the address "localhost" to be available, while having an IP address also. And now there is no way to do that, because "localhost" is changed automatically to the address 0.0.0.0 when having an IP address. When 0.0.0.0 is automatically set "localhost" no longer works from browsers. I managed to solve this by altering the code in sirv-cli/index.js But it would be nice to this by using parameters...

//let { local, network } = laccess({ port, hostname, https }); let { network } = laccess({ port, hostname, https }); let { local } = laccess({ port, hostname:'localhost', https });

lukeed commented 3 years ago

localhost === 0.0.0.0

Having a network address still makes it accessible via "localhost" alias.

That code you commented out is literally just display code.

tbenko73 commented 3 years ago

Yes indeed. But from the point of view of a complicated project with external dependencies requiring "localhost" is essential... The display code is clicked to open the project. And instead of opening the project at the adress localhost:8080 it opens it at the address: 0.0.0.0:8080 From that point things break on dev, because the full project works only with localhost:8080. So the user must type manually localhost every time in the browser to open the project preview instead of a click. The change I am trying to suggest is to allow choosing the display of: "localhost" or 0.0.0.0