Web application framework for Sigil (routing, middleware, static files, cookies).
- JavaScript 100%
|
David Wilson
34f1f6e8c0
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
stream-events-handler called http-response/sse-broadcast while omitting the broadcast handler positional, relying on it defaulting to identity. That default only exists in the `. opts` form (sigil-http 0.16.7+). Releases 0.16.1-0.16.6 typed the handler as a required positional; omitting it (and jumping straight to the on-connect: keyword) crashed the SSE connect with "car: expected pair" - a 500 on GET /feed, most visible when the server runs interpreted and loads one of those releases. Pass `identity` explicitly. It is correct for every release: the hub carries pre-formatted SSE strings so identity is the right handler, and the `. opts` form accepts a leading procedure too. Bumps to 0.16.1 and adds a regression test for the live-routes -> handler call contract. |
||
|---|---|---|
| assets/sigil-web/js | Fix ui-update morph: morph the element itself (outerHTML), not innerHTML | |
| docs | Resolve [DW] doc review comments; rename flash-message -> sg-flash-message | |
| src/sigil | Fix live-stream SSE endpoint 500 by passing an explicit broadcast handler | |
| test | Fix live-stream SSE endpoint 500 by passing an explicit broadcast handler | |
| .gitignore | Untrack .sigil/deps/ symlinks; ignore .sigil/ | |
| .woodpecker.yml | Bump CI pin to sigil v0.14.3 | |
| CHANGELOG.md | Fix live-stream SSE endpoint 500 by passing an explicit broadcast handler | |
| dev-redirects.sgl | Convert to standalone package | |
| package.sgl | Fix live-stream SSE endpoint 500 by passing an explicit broadcast handler | |
| README.md | Migrate to 0.9.1 transitive deps with version ranges and lockfile | |
| sigil.lock | Bump sigil-http pin to ^0.18.0 for serve-file Range support | |
sigil-web
Web application framework for Sigil. Provides routing, middleware, static file serving, cookies, and a server-driven UI library for building interactive web applications.
Usage
Routing
(import (sigil web routes))
;; Define routes with pattern matching
(define app
(router
(route GET "/" home-handler)
(route GET "/users/:id" user-handler)
(route POST "/api/login" login-handler)
(route ANY "/static/*path" static-handler)))
;; Extract path parameters in handlers
(define (user-handler request)
(let ((id (path-param request "id")))
...))
Middleware
(import (sigil web middleware))
;; Compose middleware around a handler
(define handler
(wrap-middleware app
(cors-middleware '("*"))
(content-type-middleware "text/html")
(not-found-middleware)))
;; Or use the chain style
(define handler
(chain app
(with-cors "*")
(with-content-type "text/html")
(with-not-found)))
Static Files
(import (sigil web static))
;; Serve files from a directory with MIME type detection
(define static-handler (make-static-handler "public/"))
Cookies
(import (sigil web cookies))
;; Read cookies from a request
(cookie-ref request "session_id")
;; Set a cookie on a response
(set-cookie response "session_id" "abc123"
'((path . "/") (http-only . #t)))
Server-Driven UI
(import (sigil web ui))
;; Send SSE events for real-time updates
(sse-morph target: "#chat" mode: "append"
content: `(div (@ (class "msg")) "Hello!"))
;; Return HTML with merge headers
(sigil-ui-response target: "#results" mode: "inner"
content: `(ul ,@(map render-item items)))
Live Development
(import (sigil web dev))
(define dev (make-dev-broadcast))
;; Wire (dev-sse-handler) into your router at /__dev/events
;; Then trigger browser refresh:
(dev-reload!)
Modules
(sigil web routes)-- path-based routing with named and splat parameters(sigil web middleware)-- composable middleware (CORS, content-type, not-found)(sigil web static)-- static file serving with directory traversal protection(sigil web cookies)-- cookie parsing and setting(sigil web ui)-- server-driven hypermedia (SSE morphing, forms, modals, data tables)(sigil web dev)-- live development broadcast and error overlay
Dependencies
- sigil-stdlib
- sigil-http
- sigil-sxml
- sigil-nrepl
Build
sigil deps install
sigil build
sigil test
License
BSD-3-Clause