Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/BuiltInTools/HotReloadClient/Web/BrowserRefreshServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ internal sealed class BrowserRefreshServer(
ILoggerFactory loggerFactory,
string middlewareAssemblyPath,
string dotnetPath,
string? autoReloadWebSocketHostName,
int? autoReloadWebSocketPort,
string? browserWebSocketHostName,
int? browserWebSocketPort,
int? browserWebSocketSecurePort,
bool suppressTimeouts)
: AbstractBrowserRefreshServer(middlewareAssemblyPath, logger, loggerFactory)
{
Expand All @@ -44,8 +45,9 @@ protected override bool SuppressTimeouts

protected override async ValueTask<WebServerHost> CreateAndStartHostAsync(CancellationToken cancellationToken)
{
var hostName = autoReloadWebSocketHostName ?? "127.0.0.1";
var port = autoReloadWebSocketPort ?? 0;
var hostName = browserWebSocketHostName ?? "127.0.0.1";
var port = browserWebSocketPort ?? 0;
var securePort = browserWebSocketSecurePort ?? 0;

var supportsTls = await IsTlsSupportedAsync(cancellationToken);

Expand All @@ -55,7 +57,7 @@ protected override async ValueTask<WebServerHost> CreateAndStartHostAsync(Cancel
builder.UseKestrel();
if (supportsTls)
{
builder.UseUrls($"https://{hostName}:{port}", $"http://{hostName}:{port}");
builder.UseUrls($"https://{hostName}:{securePort}", $"http://{hostName}:{port}");
}
else
{
Expand Down Expand Up @@ -112,7 +114,7 @@ private ImmutableArray<string> GetServerUrls(IHost server)

Debug.Assert(serverUrls != null);

if (autoReloadWebSocketHostName is null)
if (browserWebSocketHostName is null)
{
return [.. serverUrls.Select(s =>
s.Replace("http://127.0.0.1", "ws://localhost", StringComparison.Ordinal)
Expand Down
5 changes: 3 additions & 2 deletions src/BuiltInTools/Watch/AppModels/WebApplicationAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ private static string GetMiddlewareAssemblyPath()
context.LoggerFactory,
middlewareAssemblyPath: GetMiddlewareAssemblyPath(),
dotnetPath: context.EnvironmentOptions.MuxerPath,
autoReloadWebSocketHostName: context.EnvironmentOptions.AutoReloadWebSocketHostName,
autoReloadWebSocketPort: context.EnvironmentOptions.AutoReloadWebSocketPort,
browserWebSocketHostName: context.EnvironmentOptions.BrowserWebSocketHostName,
browserWebSocketPort: context.EnvironmentOptions.BrowserWebSocketPort,
browserWebSocketSecurePort: context.EnvironmentOptions.BrowserWebSocketSecurePort,
Comment on lines +62 to +64
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a new environment variable and modifies the browser refresh server's port binding behavior, but there are no new tests to verify this functionality. Consider adding a test that verifies when both DOTNET_WATCH_AUTO_RELOAD_WS_PORT and DOTNET_WATCH_AUTO_RELOAD_WSS_PORT are set with TLS enabled, the HTTP and HTTPS endpoints bind to their respective ports correctly.

Copilot uses AI. Check for mistakes.
suppressTimeouts: context.EnvironmentOptions.TestFlags != TestFlags.None);
}

Expand Down
10 changes: 6 additions & 4 deletions src/BuiltInTools/Watch/Context/EnvironmentOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ internal sealed record EnvironmentOptions(
bool SuppressEmojis = false,
bool RestartOnRudeEdit = false,
LogLevel? CliLogLevel = null,
string? AutoReloadWebSocketHostName = null,
int? AutoReloadWebSocketPort = null,
string? BrowserWebSocketHostName = null,
int? BrowserWebSocketPort = null,
int? BrowserWebSocketSecurePort = null,
string? BrowserPath = null,
TestFlags TestFlags = TestFlags.None,
string TestOutput = "")
Expand All @@ -56,8 +57,9 @@ internal sealed record EnvironmentOptions(
SuppressEmojis: EnvironmentVariables.SuppressEmojis,
RestartOnRudeEdit: EnvironmentVariables.RestartOnRudeEdit,
CliLogLevel: EnvironmentVariables.CliLogLevel,
AutoReloadWebSocketHostName: EnvironmentVariables.AutoReloadWSHostName,
AutoReloadWebSocketPort: EnvironmentVariables.AutoReloadWSPort,
BrowserWebSocketHostName: EnvironmentVariables.AutoReloadWSHostName,
BrowserWebSocketPort: EnvironmentVariables.AutoReloadWSPort,
BrowserWebSocketSecurePort: EnvironmentVariables.AutoReloadWSSPort,
BrowserPath: EnvironmentVariables.BrowserPath,
TestFlags: EnvironmentVariables.TestFlags,
TestOutput: EnvironmentVariables.TestOutputDir
Expand Down
1 change: 1 addition & 0 deletions src/BuiltInTools/Watch/Context/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static LogLevel? CliLogLevel

public static string? AutoReloadWSHostName => Environment.GetEnvironmentVariable("DOTNET_WATCH_AUTO_RELOAD_WS_HOSTNAME");
public static int? AutoReloadWSPort => ReadInt("DOTNET_WATCH_AUTO_RELOAD_WS_PORT");
public static int? AutoReloadWSSPort => ReadInt("DOTNET_WATCH_AUTO_RELOAD_WSS_PORT");
public static string? BrowserPath => Environment.GetEnvironmentVariable("DOTNET_WATCH_BROWSER_PATH");

private static bool ReadBool(string variableName)
Expand Down
Loading