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

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

Closed
OrganicCat opened this issue Mar 22, 2018 · 7 comments
Closed

Comments

@OrganicCat
Copy link

OrganicCat commented Mar 22, 2018

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
@kuceb
Copy link
Contributor

kuceb commented 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

@kuceb kuceb added the stage: needs information Not enough info to reproduce the issue label Mar 25, 2018
@OrganicCat
Copy link
Author

OrganicCat commented Mar 26, 2018

This is not true for a webpack build set up like so:

devServer: {
        historyApiFallback: true,
        allowedHosts: ['.localhost']
    }

This requires no additional setup in my hosts file, which is good because our program requires us to set up a lot of dynamic subdomains. Now if this were deployed in a remote location, yes that would require additional setup. But locally, no.

Additionally, if this is going to be classified as a feature, please at least add warning info if someone is attempting this, or notes or something, because right now cypress doesn't work with no useful information given.

@vedmant
Copy link

vedmant commented Apr 20, 2018

I have the same problem, trying to open http://booking.localhost:8080 results in:

Error: getaddrinfo ENOTFOUND booking.localhost booking.localhost:8080
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26

I can open this page in any browser without problems.

@mathieuseguin
Copy link

exact same problem here

@brian-mann
Copy link
Member

brian-mann commented 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

@mathieuseguin
Copy link

works like a charm, thanks for the quick answer @brian-mann!

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels Jun 20, 2018
struan added a commit to mysociety/fixmystreet that referenced this issue May 20, 2019
Add the hosts config option, from
cypress-io/cypress#1488 (comment)
to the cypress config so we can access *.locahost. Then use those in the
cobrand tests, as well as allowing them as cobrands by default in the
FixMyStreet server setup.

NB: need to set fixmystreet.localhost as the FixMyStreet BASE_URL
otherwise form submissions can go to localhost and then you get a
cypress cross origin security error.
struan added a commit to mysociety/fixmystreet that referenced this issue May 20, 2019
Add the hosts config option, from
cypress-io/cypress#1488 (comment)
to the cypress config so we can access *.locahost. Then use those in the
cobrand tests, as well as allowing them as cobrands by default in the
FixMyStreet server setup.

NB: need to set fixmystreet.localhost as the FixMyStreet BASE_URL
otherwise form submissions can go to localhost and then you get a
cypress cross origin security error.
struan added a commit to mysociety/fixmystreet that referenced this issue May 28, 2019
Add the hosts config option, from
cypress-io/cypress#1488 (comment)
to the cypress config so we can access *.locahost. Then use those in the
cobrand tests, as well as allowing them as cobrands by default in the
FixMyStreet server setup.

NB: need to set fixmystreet.localhost as the FixMyStreet BASE_URL
otherwise form submissions can go to localhost and then you get a
cypress cross origin security error.
@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Jul 23, 2019
@jennifer-shehane
Copy link
Member

Closing as resolved.

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

No branches or pull requests

6 participants