Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access server over local network #70

Closed
mhkeller opened this issue Jun 26, 2020 · 9 comments · Fixed by #71
Closed

Can't access server over local network #70

mhkeller opened this issue Jun 26, 2020 · 9 comments · Fixed by #71

Comments

@mhkeller
Copy link
Contributor

When I launch a server via sirv-cli, I can't access that server from another computer on the local network. I put together this reproduction repo so you can see how this issue doesn't occur with two other libraries.

I tried it with -c and --cors but that didn't fix it. If I manually set the local ip address via -H that does fix it.

@lukeed
Copy link
Owner

lukeed commented Jun 26, 2020

Hey,

You have to specify --host if you want it exposed to the network. If you leave it like that, it's the same as --host 0.0.0.0 but you can customize it if desired. The set of 0s will expose it to your network (address shown in console) so that you can do mobile testing, for example.

By default, it's purely a localhost server (aka, private) since that's all a server needs -- and it's a better default to have, especially when coffeeshops/shared spaces were a thing.

@mhkeller
Copy link
Contributor Author

Haha I vaguely remember coffeeshops. Got it. I think maybe adding that you can expose it to the local network by setting --host 0.0.0.0 would be a useful addition to the readme – I for sure wouldn't have figured that out. I thought trying the cors option was going to fix it (after fiddling with my local apache config for an ill-advised hour 🤦‍♂️). That for sure makes sense that this is the more secure default.

@mhkeller
Copy link
Contributor Author

Maybe adding a line to the default console output could be helpful for people who may be coming from svelte template land and might not know to look at sirv. Something like this perhaps?

Your application is ready!~

- Local: http://0.0.0.0:8080

Hint: Set `--host 0.0.0.0` to expose on the local network

@mhkeller
Copy link
Contributor Author

I'd be happy to do a PR to help take the load off!

@lukeed
Copy link
Owner

lukeed commented Jun 26, 2020

Ah ya, if you're up for a PR can you add a section to the CLI's readme, above the HTTP/2 section?

I don't think it should live inside the CLI text output. I don't know if I consider sirv-cli primarily a dev tool. But adding it as a an example in the helptext sounds like a good addition!

The svelte templates have updated a lotttt wrt sirv-cli flags. I think it used to be in there as a default, but rolled back for security concerns.

@Rich-Harris
Copy link
Contributor

FWIW I think @mhkeller makes a good point about people consuming sirv indirectly — it's not clear from this...

sirv-cli screenshot

...that there's a package called 'sirv' involved, so people might not know where to look. Given that similar packages do expose the server to the network, I can definitely see how it could be a source of confusion. Perhaps as an alternative/addition to this...

Your application is ready!~

- Local: http://localhost:8080
- Network: use `--host` to expose to the network

...it'd be worth pointing people to the project directly:

Your application is ready!~

- Local: http://localhost:8080

Visit https://github.com/lukeed/sirv for more info

@lukeed
Copy link
Owner

lukeed commented Jun 26, 2020

I like how both of you interpret my ~! 😆

Yeah, I've been thinking about it and I think it would be better to show a --host message in the absence of the flag.
@mhkeller If you open that PR for readme and/or the hint, I'll fiddle with the styling.

Thanks!

@mhkeller
Copy link
Contributor Author

Haha woops that's my typo transposing the ~!!

So to recap, @lukeed you're preferring this proposal?

Your application is ready~! 🚀

- Local: http://localhost:8080
- Network: use `--host` to expose to the network

@lukeed
Copy link
Owner

lukeed commented Jun 26, 2020

Yup, some variant of that should do the trick. Don't need my name showing up front & center

mhkeller added a commit to mhkeller/sirv that referenced this issue Jun 26, 2020
mhkeller added a commit to mhkeller/sirv that referenced this issue Jun 26, 2020
lukeed added a commit that referenced this issue Jun 26, 2020
* improvement(sirv-cli): Add local network info (#70)

* test(serve-cli): Add test for new example

* fix: update bin example

* chore: readme section

* chore: tweak styling

Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants