website/src/app.lisp

44 lines
1.2 KiB
Common Lisp
Raw Normal View History

2024-02-13 20:34:31 +09:00
(uiop:define-package #:hp/app
2024-02-02 01:07:19 +09:00
(:use #:cl)
2024-02-13 20:34:31 +09:00
(:local-nicknames (#:jg #:jingle))
2024-02-14 01:18:20 +09:00
(:local-nicknames (#:fbr #:ningle-fbr))
2024-02-24 20:31:06 +09:00
(:local-nicknames (#:pi #:piccolo))
(:local-nicknames (#:cmp #:hp/components/*))
2024-02-02 01:07:19 +09:00
(:import-from #:lack)
2024-02-14 00:15:37 +09:00
(:export #:*app*
#:update-routes))
2024-02-02 01:07:19 +09:00
(in-package #:hp/app)
2024-02-14 00:15:37 +09:00
(defparameter *raw-app* (jg:make-app))
2024-02-24 20:31:06 +09:00
(defmethod jg:not-found ((app jg:app))
(jg:with-html-response
(jg:set-response-status 404)
(pi:element-string (cmp:not-found-page))))
2024-02-14 00:15:37 +09:00
(defun update-routes ()
2024-02-14 01:18:20 +09:00
(fbr:enable-file-based-routing *raw-app*
:system "hp"
2024-02-25 14:11:43 +09:00
:directory "src/routes"))
2024-02-14 00:15:37 +09:00
(update-routes)
2024-02-24 18:18:24 +09:00
(defun exist-public-file-p (path)
(and (not (string= path "/"))
(let ((pathname (probe-file (concatenate 'string "public" path))))
(and pathname
(pathname-name pathname)))))
2024-02-02 01:07:19 +09:00
(defparameter *app*
2024-02-24 11:44:10 +09:00
(lack:builder :accesslog
(:static
2024-02-24 18:18:24 +09:00
:path (lambda (path)
(if (exist-public-file-p path)
path
nil))
2024-02-24 11:44:10 +09:00
:root (asdf:system-relative-pathname :hp "public/"))
2024-02-14 00:15:37 +09:00
*raw-app*))
2024-02-02 01:07:19 +09:00
; for clackup cmd
*app*