Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f9650347225b2e42b2e45419f4b98435c432c0a295b25fd7e1a7dc219024f8de
sha512=ab19e04bd6f941b769f75fc10114f3f1948cb55ed65e6f4ab8ddbf51987b18594cbb5ad4af24eeb3eb24f735e967d9e0a07112f5b7e53c2fc976cb3e5b5cdee7
Description
Live reloading for Dream applications
Added to opam-repository:
README
Dream Live Reload
Live reloading for Dream applications.
Usage
Add the Dream_livereload middleware and route to your Dream application:
let () =
Dream.run
@@ Dream.logger
@@ Dream_livereload.inject_script () (* <-- *)
@@ Dream.router [
Dream.get "/" (fun _ -> Dream.html "Hello World!");
Dream_livereload.route (); (* <-- *)
]
@@ Dream.not_foundand dream-livereload to dune:
(executable
(name my_app)
(libraries dream dream-livereload))
This does two things:
- The middleware injects a script into the HTML documents sent by your application (HTTP responses with the
Content-Type: text/html). The script opens a WebSocket connection to the server. When the connection is lost, the script tries to re-connect for 10 seconds, and upon a successfull re-connection, refreshes the current page. - The route is the HTTP endpoint used for the WebSocket connection. It does nothing but hold open the WebSocket connection.
This allows automating part of your workflow: when you rebuild your project and start a new instance of your server, the client will automatically detect it and refresh the page.
To automate your workflow completely, you can use a script to automatically rebuild and restart your server on filesystem changes:
#!/usr/bin/env bash
source_dirs="lib bin"
args=${*:-"bin/server.exe"}
cmd="dune exec ${args}"
function sigint_handler() {
kill "$(jobs -pr)"
exit 1
}
trap sigint_handler SIGINT
while true; do
dune build
$cmd &
fswatch -r -1 $source_dirs
printf "\nRestarting server.exe due to filesystem change\n"
kill "$(jobs -pr)"
doneThis will watch the directories bin/ and lib/ and restart the server at bin/server.exe on any changes.
Dependencies (6)
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building dream-livereload with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.2.0 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure