mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 10:40:45 -08:00
Enabled extend-routing
This commit is contained in:
parent
73f029a0aa
commit
27215a9a3f
3 changed files with 57 additions and 27 deletions
|
|
@ -304,6 +304,7 @@ the default answer. (Private)"
|
||||||
&key
|
&key
|
||||||
(host "0.0.0.0")
|
(host "0.0.0.0")
|
||||||
(port 8080)
|
(port 8080)
|
||||||
|
(extended-routing nil)
|
||||||
(boot-file "/boot.html")
|
(boot-file "/boot.html")
|
||||||
(boot-function nil)
|
(boot-function nil)
|
||||||
(static-boot-html nil)
|
(static-boot-html nil)
|
||||||
|
|
@ -314,12 +315,13 @@ as the default route for '/' to establish web-socket connections and
|
||||||
static files located at STATIC-ROOT. If BOOT-FILE is nil no initial
|
static files located at STATIC-ROOT. If BOOT-FILE is nil no initial
|
||||||
clog-path's will be setup, use clog-path to add. The
|
clog-path's will be setup, use clog-path to add. The
|
||||||
on-connect-handler needs to indentify the path by querying the
|
on-connect-handler needs to indentify the path by querying the
|
||||||
browser. See PATH-NAME (in CLOG-LOCATION). If static-boot-js is nil
|
browser. See PATH-NAME (in CLOG-LOCATION). If EXTENDED-ROUTING is t
|
||||||
then boot.js is served from the file /js/boot.js instead of the
|
routes will match even if extend with additional / and additional
|
||||||
compiled version. If static-boot-html is t if boot.html is not present
|
paths. If static-boot-js is nil then boot.js is served from the file
|
||||||
will use compiled version. boot-function if set is called with the url
|
/js/boot.js instead of the compiled version. If static-boot-html is t
|
||||||
and the contents of boot-file and its return value replaces the
|
if boot.html is not present will use compiled version. boot-function
|
||||||
contents sent to the brower."
|
if set is called with the url and the contents of boot-file and its
|
||||||
|
return value replaces the contents sent to the brower."
|
||||||
(set-on-connect on-connect-handler)
|
(set-on-connect on-connect-handler)
|
||||||
(when boot-file
|
(when boot-file
|
||||||
(set-clog-path "/" boot-file))
|
(set-clog-path "/" boot-file))
|
||||||
|
|
@ -338,6 +340,14 @@ contents sent to the brower."
|
||||||
;; Special handling of "clog paths"
|
;; Special handling of "clog paths"
|
||||||
(let ((clog-path (gethash (getf env :path-info)
|
(let ((clog-path (gethash (getf env :path-info)
|
||||||
*url-to-boot-file*)))
|
*url-to-boot-file*)))
|
||||||
|
(unless clog-path
|
||||||
|
(when extended-routing
|
||||||
|
(maphash (lambda (k v)
|
||||||
|
(unless (equal k "/")
|
||||||
|
(when (ppcre:scan (format nil "^~A/" k)
|
||||||
|
(getf env :path-info))
|
||||||
|
(setf clog-path v))))
|
||||||
|
*url-to-boot-file*)))
|
||||||
(cond (clog-path
|
(cond (clog-path
|
||||||
(let ((file (uiop:subpathname static-root clog-path)))
|
(let ((file (uiop:subpathname static-root clog-path)))
|
||||||
(with-open-file (stream file :direction :input
|
(with-open-file (stream file :direction :input
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ the same as the clog directy this overides the relative paths used in them.")
|
||||||
(defvar *static-root* nil
|
(defvar *static-root* nil
|
||||||
"Contains the static-root setting after initialization.")
|
"Contains the static-root setting after initialization.")
|
||||||
|
|
||||||
|
(defvar *extended-routing* nil
|
||||||
|
"If true extended routing is done.")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
;; initialize ;;
|
;; initialize ;;
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
|
|
@ -35,11 +38,20 @@ the same as the clog directy this overides the relative paths used in them.")
|
||||||
(format t "Start new window handler on connection-id - ~A" connection-id))
|
(format t "Start new window handler on connection-id - ~A" connection-id))
|
||||||
(let ((body (make-clog-body connection-id)))
|
(let ((body (make-clog-body connection-id)))
|
||||||
(let* ((path (path-name (location body)))
|
(let* ((path (path-name (location body)))
|
||||||
(on-new-window (or (gethash path *url-to-on-new-window*)
|
(on-new-window (gethash path *url-to-on-new-window*)))
|
||||||
(gethash :default *url-to-on-new-window*)
|
(unless on-new-window
|
||||||
(gethash "/" *url-to-on-new-window*))))
|
(when *extended-routing*
|
||||||
|
(maphash (lambda (k v)
|
||||||
|
(unless (equal k "/")
|
||||||
|
(when (ppcre:scan (format nil "^~A/" k) path)
|
||||||
|
(setf on-new-window v))))
|
||||||
|
*url-to-on-new-window*)))
|
||||||
|
(unless on-new-window
|
||||||
|
(setf on-new-window (or (gethash :default *url-to-on-new-window*)
|
||||||
|
(gethash "/" *url-to-on-new-window*))))
|
||||||
(if on-new-window
|
(if on-new-window
|
||||||
(progn
|
(progn
|
||||||
|
(setf (connection-data-item body "clog-path") path)
|
||||||
(setf (connection-data-item body "clog-body") body)
|
(setf (connection-data-item body "clog-body") body)
|
||||||
(setf (connection-data-item body "clog-sync") (bordeaux-threads:make-lock))
|
(setf (connection-data-item body "clog-sync") (bordeaux-threads:make-lock))
|
||||||
(funcall on-new-window body))
|
(funcall on-new-window body))
|
||||||
|
|
@ -50,6 +62,7 @@ the same as the clog directy this overides the relative paths used in them.")
|
||||||
&key
|
&key
|
||||||
(host "0.0.0.0")
|
(host "0.0.0.0")
|
||||||
(port 8080)
|
(port 8080)
|
||||||
|
(extended-routing nil)
|
||||||
(boot-file "/boot.html")
|
(boot-file "/boot.html")
|
||||||
(boot-function nil)
|
(boot-function nil)
|
||||||
(static-boot-html nil)
|
(static-boot-html nil)
|
||||||
|
|
@ -58,20 +71,22 @@ the same as the clog directy this overides the relative paths used in them.")
|
||||||
(asdf:system-source-directory :clog))))
|
(asdf:system-source-directory :clog))))
|
||||||
"Inititalize CLOG on a socket using HOST and PORT to serve BOOT-FILE
|
"Inititalize CLOG on a socket using HOST and PORT to serve BOOT-FILE
|
||||||
as the default route to establish web-socket connections and static
|
as the default route to establish web-socket connections and static
|
||||||
files located at STATIC-ROOT. If CLOG was already initialized and not
|
files located at STATIC-ROOT. If EXTENDED-ROUTING is t routes will
|
||||||
shut down, this function does the same as set-on-new-window (does not
|
match even if extend with additional / and additional paths. If CLOG
|
||||||
change the static-root). If ON-NEW-WINDOW-HANDLER is nil no handler is
|
was already initialized and not shut down, this function does the same
|
||||||
set and none is removed. STATIC-ROOT by default is the \"directory
|
as set-on-new-window (does not change the static-root). If
|
||||||
CLOG is installed in ./static-files\" If the variable
|
ON-NEW-WINDOW-HANDLER is nil no handler is set and none is
|
||||||
clog:*overide-static-root* is set STATIC-ROOT will be ignored. If
|
removed. STATIC-ROOT by default is the \"directory CLOG is installed
|
||||||
BOOT-FILE is nil no default boot-file will be set for root path,
|
in ./static-files\" If the variable clog:*overide-static-root* is set
|
||||||
i.e. /. If static-boot-js is t then boot.js is served from the file
|
STATIC-ROOT will be ignored. If BOOT-FILE is nil no default boot-file
|
||||||
/js/boot.js instead of the compiled version. If static-boot-html is nil
|
will be set for root path, i.e. /. If static-boot-js is t then boot.js
|
||||||
if boot.html is not present will use compiled version. boot-function
|
is served from the file /js/boot.js instead of the compiled
|
||||||
if set is called with the url and the contents of boot-file and its
|
version. If static-boot-html is nil if boot.html is not present will
|
||||||
return value replaces the contents sent to the brower, this allows
|
use compiled version. boot-function if set is called with the url and
|
||||||
adding content for search engine optimization, see tutorial 12 for an
|
the contents of boot-file and its return value replaces the contents
|
||||||
example."
|
sent to the brower, this allows adding content for search engine
|
||||||
|
optimization, see tutorial 12 for an example."
|
||||||
|
(setf *extended-routing* extended-routing)
|
||||||
(when on-new-window-handler
|
(when on-new-window-handler
|
||||||
(set-on-new-window on-new-window-handler :path "/" :boot-file boot-file))
|
(set-on-new-window on-new-window-handler :path "/" :boot-file boot-file))
|
||||||
(unless *clog-running*
|
(unless *clog-running*
|
||||||
|
|
@ -82,6 +97,7 @@ example."
|
||||||
(clog-connection:initialize #'on-connect
|
(clog-connection:initialize #'on-connect
|
||||||
:host host
|
:host host
|
||||||
:port port
|
:port port
|
||||||
|
:extended-routing extended-routing
|
||||||
:boot-file boot-file
|
:boot-file boot-file
|
||||||
:boot-function boot-function
|
:boot-function boot-function
|
||||||
:static-boot-html static-boot-html
|
:static-boot-html static-boot-html
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,9 @@
|
||||||
</ul>"))
|
</ul>"))
|
||||||
|
|
||||||
(defun on-page1 (body)
|
(defun on-page1 (body)
|
||||||
(create-div body :content "You are in on-page1"))
|
(create-div body :content
|
||||||
|
(format nil "You are in on-page1 and got here using ~A"
|
||||||
|
(path-name (location body)))))
|
||||||
|
|
||||||
(defun on-page2 (body)
|
(defun on-page2 (body)
|
||||||
(create-div body :content "You are in on-page2")
|
(create-div body :content "You are in on-page2")
|
||||||
|
|
@ -71,8 +73,8 @@
|
||||||
(reset form)))
|
(reset form)))
|
||||||
;; We need to override the boostrap default to submit the form html style
|
;; We need to override the boostrap default to submit the form html style
|
||||||
(set-on-submit form (lambda (obj)(declare (ignore obj))()))
|
(set-on-submit form (lambda (obj)(declare (ignore obj))()))
|
||||||
(set-on-click good-button 'on-click-good)
|
(set-on-click good-button #'on-click-good)
|
||||||
(set-on-click scary-button 'on-click-scary))))
|
(set-on-click scary-button #'on-click-scary))))
|
||||||
|
|
||||||
(defun on-default (body)
|
(defun on-default (body)
|
||||||
(cond ((equalp (path-name (location body))
|
(cond ((equalp (path-name (location body))
|
||||||
|
|
@ -98,8 +100,10 @@
|
||||||
;; Setup the default route / to on-main
|
;; Setup the default route / to on-main
|
||||||
;; :boot-function allows us to add or modify our boot-files content
|
;; :boot-function allows us to add or modify our boot-files content
|
||||||
;; for search engine optimization
|
;; for search engine optimization
|
||||||
(initialize 'on-main :boot-function 'add-search-optimizations)
|
(initialize 'on-main :boot-function 'add-search-optimizations
|
||||||
|
:extended-routing t)
|
||||||
;; Navigating to http://127.0.0.1:8080/page1 executes on-page1
|
;; Navigating to http://127.0.0.1:8080/page1 executes on-page1
|
||||||
|
;; Since extended-routing is t /page1/any/thing/else also routes to /page1
|
||||||
(set-on-new-window 'on-page1 :path "/page1")
|
(set-on-new-window 'on-page1 :path "/page1")
|
||||||
;; Navigating to http://127.0.0.1:8080/page1.html executes on-page1
|
;; Navigating to http://127.0.0.1:8080/page1.html executes on-page1
|
||||||
;; There is no .html file - it is just a route to CLOG handler
|
;; There is no .html file - it is just a route to CLOG handler
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue