Skip to content

Commit 765368d

Browse files
Binds Proxy API to the same IP address as Proxy. Closes #1043 (#1046)
1 parent dc2449a commit 765368d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dev-proxy/CommandHandlers/ProxyCommandHandler.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.VisualStudio.Threading;
77
using System.CommandLine;
88
using System.CommandLine.Invocation;
9+
using System.Net;
910

1011
namespace DevProxy.CommandHandlers;
1112

@@ -25,7 +26,7 @@ public int Invoke(InvocationContext context)
2526
{
2627
var joinableTaskContext = new JoinableTaskContext();
2728
var joinableTaskFactory = new JoinableTaskFactory(joinableTaskContext);
28-
29+
2930
return joinableTaskFactory.Run(async () => await InvokeAsync(context));
3031
}
3132

@@ -40,7 +41,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
4041
var builder = WebApplication.CreateBuilder();
4142
builder.Logging.AddFilter("Microsoft.Hosting.*", LogLevel.Error);
4243
builder.Logging.AddFilter("Microsoft.AspNetCore.*", LogLevel.Error);
43-
44+
4445
// API controller is registered first and so is the last service to be disposed of when the app is shutdown
4546
builder.Services.AddControllers();
4647

@@ -59,10 +60,12 @@ public async Task<int> InvokeAsync(InvocationContext context)
5960
options.LowercaseUrls = true;
6061
});
6162

63+
var ipAddress = context.ParseResult.GetValueForOption<string?>(ProxyHost.IpAddressOptionName, _options);
64+
ipAddress ??= "127.0.0.1";
6265
builder.WebHost.ConfigureKestrel(options =>
6366
{
64-
options.ListenLocalhost(ConfigurationFactory.Value.ApiPort);
65-
_logger.LogInformation("Dev Proxy API listening on http://localhost:{Port}...", ConfigurationFactory.Value.ApiPort);
67+
options.Listen(IPAddress.Parse(ipAddress), ConfigurationFactory.Value.ApiPort);
68+
_logger.LogInformation("Dev Proxy API listening on http://{IPAddress}:{Port}...", ipAddress, ConfigurationFactory.Value.ApiPort);
6669
});
6770

6871
var app = builder.Build();

0 commit comments

Comments
 (0)