mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 02:30:42 -08:00
Added multiple paths and default routes.
This commit is contained in:
parent
e5d1aa6d05
commit
8a62348edd
2 changed files with 69 additions and 31 deletions
|
|
@ -13,18 +13,27 @@
|
|||
;; Implementation - CLOG System
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defvar *url-to-on-new-window* (make-hash-table :test 'equalp)
|
||||
"URL to on-new-window handlers")
|
||||
|
||||
(defvar *clog-running* nil "If clog running.")
|
||||
|
||||
;;;;;;;;;;;;;;;;
|
||||
;; initialize ;;
|
||||
;;;;;;;;;;;;;;;;
|
||||
|
||||
(defvar *on-new-window* nil "Store the on-new-window handler")
|
||||
|
||||
(defun on-connect (connection-id)
|
||||
(when cc:*verbose-output*
|
||||
(format t "Start new window handler on connection-id - ~A" connection-id))
|
||||
(let ((body (make-clog-body connection-id)))
|
||||
(funcall *on-new-window* body)))
|
||||
|
||||
(let* ((path (path-name (location body)))
|
||||
(on-new-window (or (gethash path *url-to-on-new-window*)
|
||||
(gethash "default" *url-to-on-new-window*)
|
||||
(gethash "/" *url-to-on-new-window*))))
|
||||
(if on-new-window
|
||||
(funcall on-new-window body)
|
||||
(put-br (html-document win) "No route to on-new-window")))))
|
||||
|
||||
(defun initialize (on-new-window-handler
|
||||
&key
|
||||
(host "0.0.0.0")
|
||||
|
|
@ -35,27 +44,34 @@
|
|||
the default route to establish web-socket connections and static files
|
||||
located at STATIC-ROOT. If CLOG was already initialized and not shut
|
||||
down, this function does the same as set-on-new-window. If the variable
|
||||
clog:*overide-static-root* is set STATIC-ROOT will be ignored."
|
||||
(if *on-new-window*
|
||||
(set-on-new-window on-new-window-handler)
|
||||
(progn
|
||||
(set-on-new-window on-new-window-handler)
|
||||
|
||||
(cc:initialize #'on-connect
|
||||
:host host
|
||||
:port port
|
||||
:boot-file boot-file
|
||||
:static-root (if (boundp '*overide-static-root*)
|
||||
*overide-static-root*
|
||||
static-root)))))
|
||||
clog:*overide-static-root* is set STATIC-ROOT will be ignored. If BOOT-FILE
|
||||
is nil no default boot-file will be set for /."
|
||||
|
||||
(set-on-new-window on-new-window-handler :path "/" :boot-file boot-file)
|
||||
|
||||
(unless *clog-running*
|
||||
(setf *clog-running* t)
|
||||
(cc:initialize #'on-connect
|
||||
:host host
|
||||
:port port
|
||||
:boot-file boot-file
|
||||
:static-root (if (boundp '*overide-static-root*)
|
||||
*overide-static-root*
|
||||
static-root))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; set-on-new-window ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun set-on-new-window (on-new-window-handler)
|
||||
"Change the on-new-window handler."
|
||||
(setf *on-new-window* on-new-window-handler))
|
||||
(defun set-on-new-window (on-new-window-handler
|
||||
&key (path "/") (boot-file "/boot.html"))
|
||||
"Set or change the on-new-window handler or set a new one for PATH
|
||||
using BOOT_FILE. If PATH is set to default will use boot-file when
|
||||
the path can not be determined."
|
||||
(cc:set-clog-path path boot-file)
|
||||
(if boot-file
|
||||
(setf (gethash path *url-to-on-new-window*) on-new-window-handler)
|
||||
(remhash path *url-to-on-new-window*)))
|
||||
|
||||
;;;;;;;;;;;;;;
|
||||
;; shutdown ;;
|
||||
|
|
@ -63,5 +79,6 @@ clog:*overide-static-root* is set STATIC-ROOT will be ignored."
|
|||
|
||||
(defun shutdown ()
|
||||
"Shutdown CLOG."
|
||||
(set-on-new-window nil)
|
||||
(clrhash *url-to-on-new-window*)
|
||||
(setf *clog-running* nil)
|
||||
(cc:shutdown-clog))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue