πŸ“š wd-41 - Awesome Go Library for Server Applications

Go Gopher mascot for wd-41

A (w)eb (d)evelopment server with automatic live-reload on file changes

🏷️ Server Applications
πŸ“‚ Server Applications
⭐ 0 stars
View on GitHub πŸ”—

Detailed Description of wd-41

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

Go Report Card wakatime

Test coverage: 67.000% πŸ˜ŒπŸ‘

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

  1. First the content of the website is copied to a temporary directory, this is the mirrored content
  2. Every mirrored file is inspected for type, if it's text/html, a delta-streamer.js script is injected
  3. The web server is started, hosting the mirrored content
  4. The delta-streamer.js in turn sets up a websocket connection to the wd-41 webserver
  5. The original file system is monitored, on any file changes:
    1. the new file is copied to the mirror (including injections)
    2. the file name is propagated to the browser via the websocket
  6. 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]     β”‚  β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
                                               β”‚                        β”‚
                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜