When I tried to serve my project locally with a specified hostname, it doesn't work and gives me an error:
> polymer serve --hostname 'test'
Starting Polyserve...
serving on port: 8080
from root: L:\Dennis\Web_Development\solari
Files in this directory are available under the following URLs
applications: http://'test':8080
reusable components: http://'test':8080/components/solari/
error: Promise rejection: Error: getaddrinfo ENOTFOUND 'test'
error: Error: getaddrinfo ENOTFOUND 'test'
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
This has to be a bug because I just copied the example described in the docs.
polymer init applicationpolymer serve --hostname 'test'No error is throw and I can access my application under http://test:8080
Opening http://test:8080 results into a DNS-Address of server test not found.
Node is unable to perform your expected result. localhost is a special hostname referring to this computer, and node is able to connect and host locally. test, however, is not. So polymer-cli is behaving as expected, because test isn't a valid hostname.
You can try this with a valid external hostname (polymer serve --hostname test.com) and see that Node errors out with an EADDRNOTAVAIL error (Error: listen EADDRNOTAVAIL 93.184.216.34:8080)
@IchordeDionysos You'll have to first let your computer know about that hostname. This can be done by adding an entry to your hosts file (Linux/Unix/OS X: /etc/hosts, Windows: C:\Windows\System32\Drivers\etc\hosts):
# ip hostname
127.0.0.1 test
127.0.0.1 project project.local # you can also add multiple names
This way the name you're trying to listen to also resolves to an IP which is essential.
@FredKSchott test is a valid hostname to Node so long it resolves to an IP. localhost is no different. You will find that if you remove the line defining localhost from your /etc/hosts file (which usually comes pre-filled with any modern OS), it will no longer resolve either -- just like test does.
I created a pull request here: https://github.com/Polymer/docs/pull/1703
Do I have to reload/restart something that the changes are applied?
@IchordeDionysos Ah of course, I forgot that local hostnames were configurable. Thanks for the clear explanation.
Try removing the quotes around test, does it work now? I get the expected results once adding test to my /etc/hosts files and running the following:
polymer serve --hostname test
Starting Polyserve...
serving on port: 8080
from root: /Users/fschott/Code/todo-polymer
Files in this directory are available under the following URLs
applications: http://test:8080
reusable components: http://test:8080/components/todo-polymer/
Yeah thanks now it works!!
Yay! In a perfect work we could be smarter about stripping quotes, but for now that's pretty low priority compared to our other work. PRs welcome if anyone is interested in adding!
The quotes shouldn't be in the documentation to begin with! If you can pinpoint me to the file where arguments are handled, I can create a PR, @FredKSchott. Thanks!
This whole time I didn't even realize that was in the docs :disappointed:
@JimPanic here's the file you'll want to edit: https://github.com/JimPanic/docs/blob/patch-1/app/1.0/docs/tools/polymer-cli.md Thanks for volunteering, we appreciate the help!
@FredKSchott I removed the quotes from the docs now as well in my PR to polymer/docs. Could you pinpoint me to the part of the arguments (hostname argument in particular) in polymer-cli itself as well? This is certainly a bug that is easily fixed.
Hmm, actually @JimPanic I can't reproduce on my machine.
fschott-macbookpro:temp fschott$ polymer serve --hostname 'test'
Starting Polyserve...
serving on port: 8080
from root: /Users/fschott/Code/temp
Files in this directory are available under the following URLs
applications: http://test:8080
reusable components: http://test:8080/components/temp/
fschott-macbookpro:temp fschott$ polymer serve --hostname "test"
Starting Polyserve...
serving on port: 8080
from root: /Users/fschott/Code/temp
Files in this directory are available under the following URLs
applications: http://test:8080
reusable components: http://test:8080/components/temp/
It might just be a windows thing, let start with removing the quotes from the documentation for now and revisit later. I'm much more hesitant to add in OS-specific fixes if there's no direct need just yet.
Could you try the same with single quotes as well, please? This is not necessarily an OS-specific fix, but rather input sanitization. A warning could suffice as well.
I do both in the example I posted above (reformatted for clarify)
Ah, cool. Yeah I don't think it is reproducible on any sane shell. I hope the changes in my PR will make it into the docs. My colleague had a similar problem thus found this issue and a lot of other colleagues are working on Windows as well. With wider adoption of Polymer this number of users will only increase.
I just tested it on a colleague's Windows machine: this is an issue with cmd.exe. PowerShell works the same as any UNIX shell in this regard and strips the single and double quotes. cmd.exe strips double quotes but not single quotes.
(╯°□°)╯︵ ┻━┻
Yep, pretty much :)
how can I change the localhost path to
https://localhost:8080