web/server: first basically working fileserver
This commit is contained in:
parent
d894a861b2
commit
504aaf0f92
3 changed files with 24 additions and 5 deletions
1
test/docs/demo.html
Normal file
1
test/docs/demo.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Hello Fileserver!
|
|
@ -6,7 +6,10 @@
|
||||||
|
|
||||||
(let ((cfg (config:add *config* :server
|
(let ((cfg (config:add *config* :server
|
||||||
:class 'server:config
|
:class 'server:config
|
||||||
:port "8899"))))
|
:port "8899"
|
||||||
|
:routes
|
||||||
|
`((nil server:fileserver
|
||||||
|
:doc-root ,(t:test-path "" "docs")))))))
|
||||||
|
|
||||||
(let ((cfg (config:add *config* :client
|
(let ((cfg (config:add *config* :client
|
||||||
:class 'client:config
|
:class 'client:config
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
(:local-nicknames (:config :scopes/config)
|
(:local-nicknames (:config :scopes/config)
|
||||||
(:core :scopes/core))
|
(:core :scopes/core))
|
||||||
(:export #:config #:address #:port #:routes
|
(:export #:config #:address #:port #:routes
|
||||||
#:*listener* #:setup #:start #:stop))
|
#:*listener* #:setup #:start #:stop
|
||||||
|
#:fileserver #:message-handler))
|
||||||
|
|
||||||
(in-package :scopes/web/server)
|
(in-package :scopes/web/server)
|
||||||
|
|
||||||
|
@ -32,10 +33,15 @@
|
||||||
(defun stop (ctx)
|
(defun stop (ctx)
|
||||||
(clack:stop (listener ctx)))
|
(clack:stop (listener ctx)))
|
||||||
|
|
||||||
(defun fileserver (ctx env doc-root)
|
(defun fileserver (ctx env &key doc-root)
|
||||||
(let* ((rel-path (str:join "/" (getf env :messaage-head)))
|
(print env)
|
||||||
|
(let* ((message-head (getf env :message-head))
|
||||||
|
(rel-path (str:join "/" (cdr message-head)))
|
||||||
(file-app (make-instance 'lack/app/file:lack-app-file
|
(file-app (make-instance 'lack/app/file:lack-app-file
|
||||||
:file rel-path :root doc-root)))
|
:file rel-path :root doc-root)))
|
||||||
|
(format t "~&fileserver: doc-root ~s, rel-path ~s, message-head ~s~%"
|
||||||
|
doc-root rel-path message-head)
|
||||||
|
(format t "~&file path: ~s~%" (merge-pathnames rel-path doc-root))
|
||||||
(lack/component:call file-app env)))
|
(lack/component:call file-app env)))
|
||||||
|
|
||||||
(defun message-handler (ctx env)
|
(defun message-handler (ctx env)
|
||||||
|
@ -43,9 +49,18 @@
|
||||||
'(200 (:content-type "text/plain") ("Hello World!")))
|
'(200 (:content-type "text/plain") ("Hello World!")))
|
||||||
|
|
||||||
(defun select-app (ctx env)
|
(defun select-app (ctx env)
|
||||||
|
(dolist (r (routes (core:config ctx)))
|
||||||
|
(if (match (car r) nil)
|
||||||
|
(progn
|
||||||
|
(setf (getf env :message-head) (str:split "/" (getf env :path-info)))
|
||||||
|
(format t "~&route: ~s~%" r)
|
||||||
|
(return-from select-app
|
||||||
|
#'(lambda ()
|
||||||
|
(apply (cadr r) ctx env (cddr r)))))))
|
||||||
#'(lambda () (message-handler ctx env)))
|
#'(lambda () (message-handler ctx env)))
|
||||||
|
|
||||||
(defun match (pattern path))
|
(defun match (pattern path)
|
||||||
|
t)
|
||||||
|
|
||||||
;;;; server context (= service)
|
;;;; server context (= service)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue