http-server icon indicating copy to clipboard operation
http-server copied to clipboard

index.html change but doesn't have any auto refreshing must to manual refresh

Open HypeNeutron opened this issue 2 years ago • 4 comments

Environment Versions

  1. OS Type
  2. Node version: 18.6.0
  3. http-server version: 14.1.1

Expected result

  • auto-refreshing when any in index.html change

Actual result

  • index.html change but doesn't have any auto refreshing must to manual refresh

HypeNeutron avatar Jan 26 '23 06:01 HypeNeutron

That seems like something you would have to program yourself because it would require client-side scripting. Once a server sends a webpage, it stops communicating with the client until the client makes another request. Therefore, the server can't tell your browser that index.html has changed unless you send a request yourself.

mfrancis33 avatar May 16 '23 01:05 mfrancis33

So what are the chances of the http-server binary adding support for a custom handler? Looking at lib/http-server.js, it does take a before option that would allow wiring up a project specific handler. Then it would be up to that handler to implement a change watcher and do any payload injection to facilitate live reloading.

Basically what I'd like is something like:

$ http-server --before ./my_handler

And then we'd implement various functions in my_handler.js like:

  • handle(req, res) basic stateless handler that needs no options
  • or createHandler(options) => ((req, res) => void) a handler constructor that take some of the server options like { root, logFn } to name a couple

If you'd be open to such a PR, I'll give it a go.

jcorbin avatar Oct 16 '23 22:10 jcorbin

what are the chances

Very low. This project had no merged PRs for a year. Also this issue is a duplicate of https://github.com/http-party/http-server/issues/446 (though your proposed solution is more generic).

zbynek avatar Oct 17 '23 23:10 zbynek

This issue has been inactive for 180 days

github-actions[bot] avatar Apr 15 '24 12:04 github-actions[bot]