-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.lisp
65 lines (62 loc) · 1.87 KB
/
app.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ql:quickload :like-certain-board)
(defpackage like-certain-board.app
(:use :cl :lack.middleware.session.state.cookie :lack.session.store.dbi)
(:import-from :lack.builder
:builder)
(:import-from :ppcre
:scan
:regex-replace)
(:import-from :like-certain-board.web
:*web*)
(:import-from :like-certain-board.config
:config
:productionp
:*static-directory*)
(:import-from :like-certain-board.db
:connection-settings)
(:import-from :lack.response
:make-response
:finalize-response
:response-set-cookies))
(in-package :like-certain-board.app)
(builder
(:static
:path (lambda (path)
(if (ppcre:scan "^(?:/images/|/css/|/js/|/robot\\.txt$|/favicon\\.ico$)" path)
path
nil))
:root *static-directory*)
(if (productionp)
nil
:accesslog)
(if (getf (config) :error-log)
`(:backtrace
:output ,(getf (config) :error-log))
nil)
(:session
:store (make-dbi-store :connector (lambda ()
(apply #'dbi:connect
(like-certain-board.db:connection-settings))))
:state (make-cookie-state
:httponly t
:cookie-key "lack.session"
:samesite :strict
:secure t
:expires 1800))
(:csrf
:one-time t
:block-app (lambda (app env)
(let ((user-agent (gethash "user-agent" (getf env :headers))))
(if (cl-ppcre:scan "^Monazilla/1.00" user-agent)
(funcall app env)
'(403
(:content-type "text/plain"
:content-length 9)
("Forbidden"))))))
(if (productionp)
nil
(lambda (app)
(lambda (env)
(let ((datafly:*trace-sql* t))
(funcall app env)))))
*web*)