4 ms·
OK. I just took a look at the project, and I was wrong. I'm not using the file watcher anymore because I change my architecture (from an SPA to a traditional se
by christophilus 2y ago
OK. I just took a look at the project, and I was wrong. I'm not using the file watcher anymore because I change my architecture (from an SPA to a traditional server-rendered application).
I run bun in `--watch` mode which means the server restarts when I make changes.
The live-reload logic is around 100 LOC.
To make the client refresh when the server restarts, I wrote a little middleware function that runs in dev mode, but not production. It inspects the response, and if it detects a `text/html` response, it replaces `</body>` with `<script>...</script></body>` where the script performs a long-poll fetch to an endpoint that the middleware also injects (listening on `/{someuuid}`). If the long-poll connection drops, the client begins a reconnect loop, and once it reconnects, it reloads.
That's the gist of it, anyway. It's not as complex as it sounds, and it works quite well for my needs.