Autoreload with Racket web server
When working on a project involving the Racket web server, I felt I needed an autoreload function that would restart my application when I make changes to the code. This is something already built into koyo, a Racket web framework, but for this project I’m only using koyo components selectively, so this was not available to me out-of-the-box.
Then I thought - hey - that function doesn’t have to be inside the application, it could just as well be an external process (the unix way!). A simple program watching certain files and restarting the application when any of the files change.
And such program exists - in fact, more than one. I used the simplest one available to me - reflex (it only needs libc, no kidding!), available in Debian and Nix (among others).
In order to start an autoreloading racket web server during development, I do:
$ reflex -r '.*\.rkt' -s -- racket main.rkt
The -s
flag specifies that the child process is a long-running service
rather than a one-off command.
Hope this is useful.