diff --git a/source/clog-connection-websockets.lisp b/source/clog-connection-websockets.lisp index 69a6206..92ce024 100644 --- a/source/clog-connection-websockets.lisp +++ b/source/clog-connection-websockets.lisp @@ -396,6 +396,8 @@ the contents sent to the brower." (,*compiled-boot-js*))) ((ppcre:scan "^(?:/clog$)" path) (clog-server env)) + ((plugin-path path) + (lack/middleware/static::call-app-file (plugin-path path) env)) (t (lack/middleware/static::call-app-file *static-root* env))))))) ;; Wrap lack middlewares @@ -426,6 +428,19 @@ the contents sent to the brower." (format t "Boot file for path / : ~A~%" boot-file) *client-handler*) +(defun add-plugin-path (regex static-path) + "When a path to the webserver matches REGEX resolve the static file using +STATIC-PATH" + (setf (gethash regex *plugin-paths*) static-path)) + +(defun plugin-path (path) + (block ret-static-path + (maphash (lambda (k v) + (when (ppcre:scan k path) + (return-from ret-static-path v))) + *plugin-paths*) + nil)) + ;;;;;;;;;;;;;;;;;;;;;;;;; ;; shutdown-connection ;; ;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/source/clog-connection.lisp b/source/clog-connection.lisp index 3e98dce..61fd120 100644 --- a/source/clog-connection.lisp +++ b/source/clog-connection.lisp @@ -41,6 +41,7 @@ script." (*reconnect-delay* variable) (*static-root* variable) (*clog-port* variable) + (*plugin-paths* variable) (initialize function) (random-port function) @@ -49,6 +50,7 @@ script." (set-clog-path function) (get-connection-data function) (delete-connection-data function) + (add-plugin-path function) "CLOG system utilities" @@ -93,6 +95,8 @@ script." (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 *plugin-paths* (make-hash-table* :test #'equalp) "Path regex -> static-root") + (defvar *on-connect-handler* nil "New connection event handler.")