devf

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: EUPL-1.2 Imports: 20 Imported by: 0

Documentation

Overview

package devf provides livereload webserver for developers (inspired by devd). It attempts to do one thing and do it well: serve as a reverse proxy while injecting some JS to support livereloading.

The livereload is triggered by a std-input newline or some OS-signals (usually provided by another tool).

Usage:

devf [flags] <http-url-or-local-folders> [-- <sub-command>]
# or using go run:     go run code.pfad.fr/devf@main [flags] <http-url-or-local-folders> [-- <sub-command>]
# or using nix flakes: nix run git+https://code.pfad.fr/devf [flags] <http-url-or-local-folders> [-- <sub-command>]

If <http-url-or-local-folders> contains `://`, it will be interpreted as a URL, otherwise as a local folder (multiple folders are supported: they will be looked up in order).

The flags are:

-addr string
	address to listen to (default ":8080")
-sig value
	comma-separated list of signals which will trigger a reload
	(instead of stdin newline): abrt,hup,int,kill,pipe,quit,term,usr1,usr2

If a <sub-command> is provided, it will be launched in the background.

Example using inotifywait on linux

Local generation of the doc of this package (make doc):

inotifywait -m -e close_write --include "\.go$" -r . | \
	devf http://localhost:8181 -- vanitydoc -addr localhost:8181

Explanation (starting from the end of the command):

  • launch vanitydoc local HTTP server on port 8181 (using <sub-command>)
  • launch devf as a reverse-proxy to vanitydoc on http://localhost:8080 (default -addr)
  • watch changes to .go files (using inotifywait)
  • trigger a webbrowser reload on every inotifywait event line

Example using modd

**/*.gohtml server.is_running {
	daemon: devf -sig hup http://localhost:8989
}

modd will send a sighup to devf (which will trigger a reload) whenever a .gohtml file changes or the `server.is_running` file is written to (I usually do that in my main.go, when the server is ready to accept connections).

To ensure that the livereload is injected on pages (especially error pages), make sure that the `Content-Type` header starts with `text/html`.

Advanced usage

If you need more control regarding the triggering of the reload, the reverse-proxying or of the local server, take a look at the livereload subpackage.

License

European Union Public License 1.2 or later (EUPL-1.2+). Using only the exported API of this library (or the CLI) is not considered "Derivative Works" (so you don't need to release your work under a EUPL-1.2 compatible license in such a case).

Directories

Path Synopsis
package livereload handles Server-sent events and injection of the livereload script into upstream HTML pages.
package livereload handles Server-sent events and injection of the livereload script into upstream HTML pages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL