ability to switch static routes at run-time

This commit is contained in:
David Botton 2024-07-01 00:30:55 -04:00
parent 144a4e2133
commit eb63715883
9 changed files with 244 additions and 237 deletions

2
clog.asd vendored
View file

@ -10,7 +10,7 @@
:description "CLOG - The Common Lisp Omnificent GUI"
:author "David Botton <david@botton.com>"
:license "BSD"
:version "1.9.0"
:version "2.2"
:serial t
:depends-on (#:clack #:websocket-driver #:alexandria #:hunchentoot #:cl-ppcre
#:bordeaux-threads #:trivial-open-browser #:parse-float #:quri

View file

@ -279,16 +279,10 @@ the contents sent to the brower."
(set-on-connect on-connect-handler)
(when boot-file
(set-clog-path "/" boot-file))
(setf *static-root* static-root)
(setf *clog-port* port)
(setf *app*
(lack:builder
(lambda (app)
(lambda (env)
;; if not static-boot-js use internal compiled boot.js
(if (and (eq static-boot-js nil)
(equalp (getf env :path-info) "/js/boot.js"))
`(200 (:content-type "text/javascript")
(,*compiled-boot-js*))
(funcall app env))))
(lambda (app)
(lambda (env)
;; Special handling of "clog paths"
@ -394,15 +388,16 @@ the contents sent to the brower."
(finish-output stream)))))))))
;; Pass the handling on to next rule
(t (funcall app env))))))
(:static :path (lambda (path)
;; Request is static path if not the websocket connection.
;; Websocket url is /clog
(cond ((ppcre:scan "^(?:/clog$)" path) nil)
(t path)))
:root static-root)
;; Handle Websocket connection
(lambda (env)
(clog-server env))))
(let* ((path (getf env :path-info)))
(cond ((and (eq static-boot-js nil)
(equalp path "/js/boot.js"))
`(200 (:content-type "text/javascript")
(,*compiled-boot-js*)))
((ppcre:scan "^(?:/clog$)" path)
(clog-server env))
(t
(lack/middleware/static::call-app-file *static-root* env)))))))
;; Wrap lack middlewares
(setf *app* (reduce #'funcall
lack-middleware-list

View file

@ -39,6 +39,8 @@ script."
(*break-on-error* variable)
(*disable-clog-debugging* variable)
(*reconnect-delay* variable)
(*static-root* variable)
(*clog-port* variable)
(initialize function)
(random-port function)
@ -89,6 +91,8 @@ script."
(defvar *break-on-error* t "Allow invoking debugger (default t)")
(defvar *disable-clog-debugging* nil "When true turns off debug hooks (default nil)")
(defvar *reconnect-delay* 7 "Time to delay in seconds for possible reconnect (default 7)")
(defparameter *static-root* nil "Contains the static-root setting after initialization.")
(defparameter *clog-port* 8080 "Port this instance of clog was started on")
(defvar *on-connect-handler* nil "New connection event handler.")

View file

@ -20,20 +20,9 @@
"Set a debug hook that is called for every event with (event data)
that must be (funcall event data).")
(defvar *overide-static-root* nil
"Override the static-root settings. This is not normally a good idea, but if
trying to run the tutorials or demos and unable to have your local directory
the same as the clog directy this overides the relative paths used in them.")
(defvar *static-root* nil
"Contains the static-root setting after initialization.")
(defvar *extended-routing* nil
"If true extended routing is done.")
(defparameter *clog-port* 8080
"Port this instance of clog was started on")
;;;;;;;;;;;;;;;;
;; initialize ;;
;;;;;;;;;;;;;;;;
@ -134,11 +123,8 @@ number is chosen."
(setf *clog-running* t)
(when (or (eql port 0) (eq port nil))
(setf port (clog-connection:random-port)))
(setf *clog-port* port)
(setf *static-root* (truename (or *overide-static-root*
static-root)))
(apply #'clog-connection:initialize
(append (list #'on-connect :static-root *static-root* :port *clog-port*)
(append (list #'on-connect :static-root static-root :port port)
rest))))
;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -17,6 +17,8 @@
(mgl-pax:define-package :clog
(:documentation "CLOG - The Common List Omnificent GUI")
(:import-from :clog-connection
:*clog-port*
:*static-root*
#:make-hash-table*
#:escape-string
#:generate-id

View file

@ -509,7 +509,9 @@ not a temporarily attached one when using select-control."
(*default-title-class* *builder-title-class*)
(*default-border-class* *builder-border-class*)
ext-panel
(win (create-gui-window obj :top 40 :left (+ *builder-left-panel-size* 5)
(win (create-gui-window obj
:top (menu-bar-height obj)
:left (+ *builder-left-panel-size* 5)
:width 645 :height 430
:client-movement *client-side-movement*))
(box (create-panel-box-layout (window-content win)

View file

@ -86,6 +86,11 @@
(lambda (obj)
(let* ((*default-title-class* *builder-title-class*)
(*default-border-class* *builder-border-class*))
(setf *static-root*
(merge-pathnames (if (equal (current-project app) "clog")
"./static-root/"
"./www/")
(format nil "~A" (asdf:system-source-directory (current-project app)))))
(input-dialog obj "Run form:"
(lambda (result)
(when result
@ -100,7 +105,9 @@
:capture-console nil
:capture-result nil
:eval-in-package "clog-user")))
:default-value entry-point))))
:default-value entry-point)
(alert-toast obj "Static Root Set"
*static-root* :color-class "w3-yellow" :time-out 3))))
(labels ((project-tree-dir-select (node dir)
(let ((filter (equalp (text-value filter-btn)
"filter")))

View file

@ -81,6 +81,13 @@
(let ((app (connection-data-item panel "builder-app-data"))
(val (text-value (entry-point panel))))
(unless (equal val "")
(setf *static-root*
(merge-pathnames (if (equal (current-project app) "clog")
"./static-root/"
"./www/")
(format nil "~A" (asdf:system-source-directory (current-project app)))))
(alert-toast panel "Static Root Set"
*static-root* :color-class "w3-yellow")
(setf clog:*clog-debug*
(lambda (event data)
(with-clog-debugger (panel

View file

@ -2,6 +2,8 @@
(defun on-open-repl-console (obj repl)
(let* ((win (on-open-file obj :title "CLOG REPL Console"
:top (+ (menu-bar-height obj) 485)
:left (+ *builder-left-panel-size* 5)
:is-console t
:closer-html "&#10752;"
:editor-use-console-for-evals t)))
@ -18,6 +20,8 @@
(*default-title-class* *builder-title-class*)
(*default-border-class* *builder-border-class*)
(win (create-gui-window obj :title "CLOG Builder REPL"
:top (menu-bar-height obj)
:left (+ *builder-left-panel-size* 5)
:has-pinner t
:keep-on-top t
:width 700 :height 480