WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Listen on all ips

Open cocoon opened this issue 1 year ago • 4 comments

I ask this as question, maybe I missed something obvious.

When I want to listen to all public IPs I thought I could use http://0.0.0.0 as URL, but it was not working. So I had to get all my current IPs and add them as List.

And when I check this line of code:

https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs#L79

it looks like it should use "ListenAnyIP" but instead it is listed in "ListenLocalhost"?

cocoon avatar Aug 09 '24 07:08 cocoon

I need to double check that.

BTW what .NET version are you using?

StefH avatar Aug 09 '24 08:08 StefH

I usually use .net 8 now.

cocoon avatar Aug 09 '24 10:08 cocoon

I tried it and moved the host check for 0.0.0.0 at top and return it as ListenAnyIP and it works:

if (urlDetail is { Port: > 0, Host: "0.0.0.0" })
 {
     kestrelOptions.ListenAnyIP(urlDetail.Port, configure);
     return;
 }
var Settings = new WireMock.Settings.WireMockServerSettings
{
    Urls = new string[] { "http://0.0.0.0:80" },
    AllowPartialMapping = true,
    StartAdminInterface = true,
};

var server = WireMockServer.Start(Settings);

WireMock NET-0 0 0 0

cocoon avatar Aug 12 '24 08:08 cocoon

Looks good.

Can you make a PR and if possible add/update a unit test?

StefH avatar Aug 13 '24 15:08 StefH

PR created and tried to add a test.

cocoon avatar Sep 04 '24 09:09 cocoon