Add public-files middleware
This commit is contained in:
parent
21c2d8aa99
commit
f7390b520c
3 changed files with 24 additions and 5 deletions
2
hp.asd
2
hp.asd
|
@ -7,4 +7,4 @@
|
|||
:depends-on ("hp/app")
|
||||
:in-order-to ((test-op (test-op "hp-tests"))))
|
||||
|
||||
(register-system-packages "lack-middleware-accesslog" '(:lack.middleware.accesslog))
|
||||
(register-system-packages "lack-middleware-static" '(:lack.middleware.static))
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
(:local-nicknames (#:pi #:piccolo))
|
||||
(:local-nicknames (#:view #:hp/view))
|
||||
(:local-nicknames (#:cmp #:hp/components/**/*))
|
||||
(:import-from #:lack.middleware.accesslog
|
||||
#:*lack-middleware-accesslog*)
|
||||
(:local-nicknames (#:mw #:hp/middleware))
|
||||
(:export #:start
|
||||
#:stop
|
||||
#:update))
|
||||
|
@ -24,8 +23,7 @@
|
|||
|
||||
(defun update ()
|
||||
(jg:clear-middlewares *app*)
|
||||
(jg:install-middleware *app* *lack-middleware-accesslog*)
|
||||
(jg:static-path *app* "/public/" "public/")
|
||||
(jg:install-middleware *app* mw:*public-files*)
|
||||
(fbr:assign-routes *app*
|
||||
:system "hp"
|
||||
:directory "src/routes"))
|
||||
|
|
21
src/middleware.lisp
Normal file
21
src/middleware.lisp
Normal file
|
@ -0,0 +1,21 @@
|
|||
(defpackage #:hp/middleware
|
||||
(:use #:cl)
|
||||
(:local-nicknames (#:jg #:jingle))
|
||||
(:import-from #:lack.middleware.static
|
||||
#:*lack-middleware-static*)
|
||||
(:export #:*public-files*))
|
||||
(in-package #:hp/middleware)
|
||||
|
||||
(defun exist-public-file-p (path)
|
||||
(let ((pathname (probe-file (concatenate 'string "public" path))))
|
||||
(and pathname (pathname-name pathname))))
|
||||
|
||||
(defparameter *public-files*
|
||||
(lambda (app)
|
||||
(funcall *lack-middleware-static*
|
||||
app
|
||||
:path (lambda (path)
|
||||
(if (exist-public-file-p path)
|
||||
path
|
||||
nil))
|
||||
:root (asdf:system-relative-pathname :hp "public/"))))
|
Loading…
Add table
Add a link
Reference in a new issue