natemcmaster / dotnet-serve

Simple command-line HTTPS server for the .NET Core CLI

Home Page:https://nuget.org/packages/dotnet-serve/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for LiveReload

daveaglick opened this issue · comments

In Wyam I finally figured out how to get LiveReload working with nothing but ASP.NET Core WebSockets.

There’s a couple parts to this:

  • An embedded JavaScript file that can be served on a well-known path.
  • Middleware that injects a script directive in every page to the embedded JS file when LiveReload is activated.
  • Middleware that establishes the LiveReload WebSocket connection with the clients.
  • A file system watcher that tells connected clients to reload their current page when the file system changes (this can even get more granular like only reloading a specific path, but I’ve found just reloading whatever the client is viewing is safer).

I think this would be a nice enhancement - is it something you’d be interested in me porting over (I can’t promise how quickly though 😄)?

Sure, I'd take a PR for this. Does this need a new command line option or other config settings? Or is there a sensible default that "just works"?

That’s a good question. It needs to inject a single <script> tag at the bottom of the page, but not sure how I feel about doing that automatically. I’ll defer to you whether it should be behind a flag or not 😄.

Let’s make it a switch first. If it’s use becomes so common that people would rather have it on by default, then we can always do that later.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 7 days.