Safsaf is a Guile web framework, written using Claude Code running Claude Opus 4.6, based off of the Guix Data Service, Nar Herder and Guix Build Coordinator codebases.
This commit is contained in:
commit
5b0e6397dc
53 changed files with 7427 additions and 0 deletions
54
examples/blog-site/blog-site.scm
Normal file
54
examples/blog-site/blog-site.scm
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
(use-modules (model)
|
||||
(views)
|
||||
(safsaf)
|
||||
(safsaf handler-wrappers csrf)
|
||||
(safsaf handler-wrappers exceptions)
|
||||
(safsaf handler-wrappers logging)
|
||||
(safsaf handler-wrappers security-headers)
|
||||
(safsaf handler-wrappers sessions)
|
||||
(safsaf response-helpers)
|
||||
(safsaf router))
|
||||
|
||||
(unless (file-exists? "static/style.css")
|
||||
(format (current-error-port)
|
||||
"error: run this from the examples/blog-site/ directory~%")
|
||||
(exit 1))
|
||||
|
||||
;; Create a shared database thread pool.
|
||||
(define pool (make-db "/tmp/blog-site.db"))
|
||||
|
||||
;; Initialise the schema.
|
||||
(db-init! pool)
|
||||
|
||||
;; Session manager — in production, use a proper secret.
|
||||
(define session-manager
|
||||
(make-session-config "change-me-in-production"
|
||||
#:cookie-name "blog-session"))
|
||||
|
||||
;; Build the blog component — handles both HTML and JSON via content negotiation.
|
||||
(define blog-routes (make-blog-component pool session-manager))
|
||||
|
||||
;; Static file serving.
|
||||
(define static-routes
|
||||
(route-group '("static")
|
||||
(route 'GET '(. path)
|
||||
(make-static-handler "./static"
|
||||
#:cache-control '((max-age . 3600))))))
|
||||
|
||||
;; Apply handler wrappers and add a catch-all 404 route.
|
||||
(define all-routes
|
||||
(wrap-routes (list blog-routes
|
||||
static-routes
|
||||
(route '* '* (lambda (request body-port)
|
||||
(not-found-response))))
|
||||
(make-exceptions-handler-wrapper #:dev? #t)
|
||||
logging-handler-wrapper
|
||||
security-headers-handler-wrapper
|
||||
(make-session-handler-wrapper session-manager)
|
||||
csrf-handler-wrapper))
|
||||
|
||||
;; Start the server.
|
||||
(let ((port 8082))
|
||||
(format #t "Listening on http://localhost:~a~%" port)
|
||||
(force-output)
|
||||
(run-safsaf all-routes #:port port))
|
||||
Loading…
Add table
Add a link
Reference in a new issue