I want to find an easy solution for the front-end team and testing team so when they working locally they can override the host header to match {tenant}.mydomain.com. Do you know how I can achieve this?
Below is my .net 7 code for checking host
var host = Request.Host.Value;
if (string.IsNullOrEmpty(host))
{
return BadRequest("Missing host header.");
}
I read that the hosts
file could be used but is not flexible and will require changes whenever you wanna test another tenant
2
Answers
It is said postman use system DNS. https://github.com/postmanlabs/postman-app-support/issues/3177
Maybe you need this.
https://hostsfileeditor.com/
or Power Toy
https://learn.microsoft.com/en-us/windows/powertoys/hosts-file-editor#filtering-host-file-entries
In Postman, this is what Environments are for.
Create separate environments for each of the host headers.
Each environment needs to contain a variable with the actual host header.
I’m assuming we are talking about host headers as described here.
What is HTTP "Host" header?
Which means adding a header called host. (Instead of changing the URL).
The instructions for adding a header in Postman can be found here.
https://learning.postman.com/docs/sending-requests/requests/#configuring-request-headers
Instead of hardcoding a value, use the environment variable. For example {{hostHeader}}.
All the tester would need to do is change the environment to match the host header they want to use.
If you are actually talking about changing the host in the URL, then its the same principle. Use environments and then have a variable for the {{baseURL}} that you use in the request.