diff options
Diffstat (limited to 'src/app.lisp')
| -rw-r--r-- | src/app.lisp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/app.lisp b/src/app.lisp new file mode 100644 index 0000000..6c8b960 --- /dev/null +++ b/src/app.lisp @@ -0,0 +1,43 @@ +(in-package #:hito) + +;;; --- Server Configuration --- + +(defvar *app* nil + "The Hunchentoot acceptor instance.") + +(defvar *port* 8080 + "Port on which HITO listens.") + +(defvar *static-directory* + (asdf:system-relative-pathname "hito" "static/") + "Path to static assets (CSS, images).") + +;;; --- Static File Serving --- + +(push (hunchentoot:create-folder-dispatcher-and-handler + "/static/" *static-directory*) + hunchentoot:*dispatch-table*) + +;;; --- Server Lifecycle --- + +(defun start (&key (port *port*)) + "Start the HITO web server. Initializes the database if needed." + (when *app* + (format t "~&Server already running on port ~D. Stop it first.~%" *port*) + (return-from start nil)) + ;; Ensure DB is ready + (init-db) + (setf *app* (make-instance 'hunchentoot:easy-acceptor + :port port + :document-root *static-directory*)) + (hunchentoot:start *app*) + (format t "~&HITO is running on port ~D.~%" port) + *app*) + +(defun stop () + "Stop the HITO web server." + (when *app* + (hunchentoot:stop *app*) + (setf *app* nil) + (format t "~&HITO stopped.~%") + t)) |