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

Add a .host() method to set a host other than 127.0.0.1 #297

Merged
merged 1 commit into from Apr 23, 2018

Conversation

mikec
Copy link

@mikec mikec commented Nov 15, 2015

This allows you to set the server hostname before making a
request. If no hostname is set then it defaults to 127.0.0.1

@tobidelius
Copy link

yes yes yes

@shults
Copy link

shults commented Apr 28, 2016

If somebody looks for an opportunity virtual hosts testing. My solution is below.

function createVhostTester(app, vhost) {
  const real = supertest(app);
  const proxy = {};

  Object.keys(real).forEach(methodName => {
    proxy[methodName] = function() {
      return real[methodName]
        .apply(real, arguments)
        .set('host', vhost);
    }
  });

  return proxy;
}

var api = createVhostTester(appInstance, 'api.example.com');
var appTest = createVhostTester(appInstance, 'app.example.com');

@saintedlama
Copy link
Contributor

@mikelax this PR could fix problems with IP V6 as well since one could pass ::1 as address 👍

@lpil
Copy link

lpil commented Aug 11, 2016

Hello! Is it likely this will get merged?

@jobackman
Copy link

Nice work! I would also love for this to be a feature in supertest 👍

@michaelBenin
Copy link

This is a great feature needed. Please consider merging. Ping.

@atomantic
Copy link

@shults your solution worked perfectly for me :)

@rockaBe
Copy link

rockaBe commented Apr 27, 2017

Will this PR ever be considered to be merged? It's 1.5 years old now .....

@KaiSchwarz-cnic
Copy link

+1

1 similar comment
@cianclarke
Copy link

+1

This allows you to set the server hostname before making a
request. If no hostname is set then it defaults to 127.0.0.1
@mikec
Copy link
Author

mikec commented Aug 15, 2017

@mikelax I fixed the conflicts and build errors, can this be merged?

@elvizcacho
Copy link

+1

1 similar comment
@ozanblk
Copy link

ozanblk commented Oct 13, 2017

+1

@KaiSchwarz-cnic
Copy link

guys, any update on this? Would be very great to see this added soon...

@lauzierj
Copy link

I believe you can do this using the example below:

supertest(app)
  .get('/path/to/thing')
  .set('host', 'api.example.com');

Express 4 then shows req.subdomains as ['api'].

@chrisveness
Copy link

+1

@KaiSchwarz-cnic
Copy link

@lauzierj many thanks for providing that example, worked nicely. So many people waiting for it and it got already added. No idea, maybe not documented? At least I had not found anything at the time I was looking for that feature.

@yadahung
Copy link

+1

@rimiti rimiti self-assigned this Apr 19, 2018
@rimiti rimiti requested review from mikelax and rimiti April 19, 2018 12:33
@rimiti rimiti added this to the v3.1.0 milestone Apr 19, 2018
@rimiti
Copy link
Contributor

rimiti commented Apr 19, 2018

Thank you for your contributions.
This feature will be include in the next release.

@rimiti rimiti changed the base branch from master to release-v3.1.0 April 23, 2018 09:37
@rimiti
Copy link
Contributor

rimiti commented Apr 23, 2018

I merge it into release-v3.1.0.

@rimiti rimiti merged commit 9c9c0ea into ladjs:release-v3.1.0 Apr 23, 2018
@rimiti rimiti mentioned this pull request Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet