question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using a subdomain with localhost will throw an error of unreachable on Mac

See original GitHub issue

Current 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

51reactions
brian-manncommented, Jun 12, 2018

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 in cypress.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.

// cypress.json
"hosts": {
  "*.localhost": "127.0.0.1"
}

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

6reactions
kucebcommented, Mar 23, 2018

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found