dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.45k stars 10.03k forks source link

Can't set a static port/endpoint of auto reload script when running dotnet watch run. #33823

Open aaronamm opened 3 years ago

aaronamm commented 3 years ago

Hello everyone

I have setup a Docker compose file with a custom image to launch ASP.NET Core MVC app with dotnet watch run. However, I can't make a browser to auto reload when some code has been changed.

This is because a container does not publish a port number that aspnetcore-browser-refresh.js use to create a WebSocket connection.

I found that we have ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT defined in https://github.com/dotnet/sdk/blob/release/5.0.2xx/src/BuiltInTools/BrowserRefresh/BrowserScriptMiddleware.cs#L23 but setting a value of ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT environment variable does not change a WebSocket endpoint. It always get a random port number whenever we run dotnet watch run and cause me to not be able to configure a published port number in a Docker compose file.

Here is a screenshot of the WebSocket issue.

image

How to reproduce an issue:

Please follow the instruction in this README https://github.com/codesanook/Codesanook.EFNote#how-to-run-the-project-locally

My development environment

Please could you help me figure it out how to make a stick port number of WebSocket in a browser reload script? Thanks.

Other useful information

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

CliXiD commented 3 years ago

I think the keypoint of this is from https://github.com/dotnet/sdk/blob/release/5.0.2xx/src/BuiltInTools/dotnet-watch/BrowserRefreshServer.cs#L45 which cause the dynamic port.

It would be great if it take a value from ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT instead of DOTNET_WATCH_AUTO_RELOAD_WS_HOSTNAME and replace scheme if it's need.

aaronamm commented 3 years ago

@CliXiD Thank you for the information. I think what you have pointed out is the right direction to solve this issue.

However, setting DOTNET_WATCH_AUTO_RELOAD_WS_HOSTNAME variable does not solve the issue since a port number is still dynamic. I wonder if we can have some way to specific a port number as well.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

thomrad commented 1 year ago

In dotnet 7 it's still not working. Any news about this issue?

chogberg commented 5 months ago

Is this possible in 8? For us migrating from e.g. js not to be able to hotreload on all parts of your app seems a bit dated