Using a subdomain with localhost will throw an error of unreachable on Mac
See original GitHub issueCurrent behavior:
If you set up a visit call to go to something like mysubdomain.localhost:4200 Cypress will not respond properly (and will not visit) because it uses the hosts file for some subdomain redirection on localhost.
Desired behavior:
I shouldn’t have to add 127.0.0.1 for EVERY subdomain I want to test on my localhost, especially if I generate these for tests. Cypress should not have to rely on the hosts file for this.
How to reproduce:
Create a server that runs on a subdomain and your local machine so the address is something like mysubdomain.localhost:4200. Attempt to run a test that goes there. It will fail unless you add
127.0.0.1 mysubdomain.localhost
to your hosts file on Mac
- Operating System: OSX
- Cypress Version: 2.10
- Browser Version: Chrome 64
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
"Could not get any response" response when using postman ...
First Go to Settings in Postman: Off the SSL certificate verification in General Tab: Off the Global Proxy Configuration and Use System Proxy...
Read more >Why is *.localhost resolved automatically on Ubuntu but not on ...
Reason is most probably the systemd-resolvd. Checking configs: root@sf:~# grep localhost /etc/hosts 127.0.0.1 localhost ::1 ip6-localhost ...
Read more >160504 – Localhost subdomains don't work - WebKit Bugzilla
Start up a local server that responds to the host header of 'mysite.localhost' on port 8000 (any port is fine) 2. Try to...
Read more >Troubleshoot the UnknownHostException error in a Java ...
UnknownHostException is a common error message in Java applications. This error typically indicates that there was a DNS resolution failure.
Read more >8. Configuration Reference — BIND 9 9.18.8 documentation
The operational functionality of BIND 9 is defined using the file named.conf, ... There are many layout styles that can assist in minimizing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure we can look into adding this. @Bkucera is right that I don’t believe this works by default - when the DNS queries come back - it will not be your machine, but we can add overrides to automatically do this.
BTW there is an undocumented option called
hosts
incypress.json
that allows you to do this. It’s undocumented because the implementation is kind of hacky but it does work, and we use it in our own internal tests so we test how cypress behaves on other domains, which are mapped back to loopback.I haven’t tried this but our e2e tests do something similar and you could do a quick search in our repo for various implementations.
Here’s one example: https://github.com/cypress-io/cypress/blob/develop/packages/driver/test/cypress.json#L4
@OrganicCat If my understanding is correct, you can’t access a subdomain on localhost without it being added to your hosts file. This is true for any browser, Cypress driven or not. Could you explain your desired behavior in this case for Cypress vs a typical web browser accessing localhost subdomains? - this could possibly be implemented as a feature