(w)eb (d)evelopment-(41)

Test coverage: 75.640% ππ
This is a simple static webserver which live reloads your web-browser on changes to the hosted files.
Usage
wd-41 s|serve <relative directory>
or wd-41 s|serve
for hosting the current work directory
Getting started
go install github.com/baalimago/wd-41@latest
You may also use the setup script:
curl -fsSL https://raw.githubusercontent.com/baalimago/wd-41/main/setup.sh | sh
Architecture
- First the content of the website is copied to a temporary directory, this is the mirrored content
- Every mirrored file is inspectd for type, if it's text/html, a
delta-streamer.js
script is injected
- The web server is started, hosting the mirrored content
- The
delta-streamer.js
in turn sets up a websocket connection to the wd-41 webserver
- The original file system is monitored, on any file changes:
- the new file is copied to the mirror (including injections)
- the file name is propagated to the browser via the websocket
- The
delta-streamer.js
script then checks if the current window origin is the updated file. If so, it reloads the page.
βββββββββββββββββ
β Web Developer β
βββββββββ¬ββββββββ
β
[writes <content>]
β
βΌ
βββββββββββββββββββββββββββββββ βββββββββββββββββββββββ
β website-directory/<content> β β file system notify β
βββββββββββββββ¬ββββββββββββββββ βββββββββββ¬ββββββββββββ
β β
β [update mirrored content]
βΌ β
ββββββββββββββββββββββ β
β ws-script injector βββββββββββββββββββββββββ
βββββββββββ¬βββββββββββ
β
β
βΌ
ββββββββββββββββββββββββββ
β tmp-abcd1234/<content> β
βββββββββββββ¬βββββββββββββ
β
[serves <content>]
β ββββββββββββββββββββββββββ
βΌ β Browser β
ββββββββββββββββββββββββββββββββ β β
β Web Server β β ββββββ βββββββββββββ β
β [localhost:<port>/<content>] βββββ[reloadβββββΌββΊβ ws β β <content> β β
ββββββββββββββββββββββββββββββββ page] β ββββββ βββββββββββββ β
β β
ββββββββββββββββββββββββββ