]> git.pond.sub.org Git - eow/blobdiff - web.lisp
Write command to terminal output. Scroll to bottom on new output.
[eow] / web.lisp
index e648f319f150cd1804c91ffddac05b5431c6a17e..ac6a94ac3134e1fa5c90f791b2574a833a7eb67a 100644 (file)
--- a/web.lisp
+++ b/web.lisp
                                   :directory (pathname-directory *this-file*)))
 
 (defparameter +templates-root+ (namestring *this-dir*))
-(defparameter +root-url+ "/eow/static/test.html")
+(defparameter +root-url+ "/eow/")
 (defparameter +web-root-base+ "/eow")
 (defparameter +web-root+ (concatenate 'string +web-root-base+ "/"))
 (defparameter +static-web-root+ (concatenate 'string +web-root+ "static/"))
 (defparameter +static-files-root+ (concatenate 'string +templates-root+ "static/"))
 (defparameter +login-page+ (concatenate 'string +static-web-root+ "login.html"))
+(defparameter +root-page-file+ "root.html")
 
 (defun string-starts-with (string prefix)
   ;; (from Hunchentoot)
 (defgeneric prompt (session minutes btus))
 (defgeneric data (session message))
 
+(defvar *empire-session*)
+
 (defun update ()
   "Send stream of updates to client"
-  (let ((s (session-value `session)))
-    (locked-queue:dequeue (update-queue s))))
+  (with-session
+    (locked-queue:dequeue (update-queue *empire-session*))))
 
 (defmethod send ((s session) string)
   "Push a javascript update fragment to the client."
 (defmethod data ((s session) message)
   (send s (parenscript:ps* `(msg ,message))))
 
-(defun login ()
-  (let ((s (session-value 'session)))
-    (if s
-       (redirect +root-url+)
-       (redirect +login-page+))))
+(defmacro with-session (&body body)
+  `(let ((*empire-session* (session-value 'session)))
+     (if *empire-session*
+        (progn ,@body)
+        (redirect +login-page+))))
 
 ;; destination of login-form
 (defun login-action ()
       (format nil "Connection error: ~a~%" e))))
 
 (defun command-action ()
-  (let ((s (session-value 'session)))
-    (empire:send-message (connection s) (get-parameter "q"))))
+  (with-session
+      (empire:send-message (connection *empire-session*) (get-parameter "q"))))
+
+(defun root-page ()
+  (with-session
+    (handle-static-file (concatenate 'string +static-files-root+ +root-page-file+))))
 
 (defun dispatch (request)
   (let ((script-name (script-name request)))
       ((string= script-name "/eow/login") 'login-action)
       ((string= script-name "/eow/command") 'command-action)
       ((or (string-equal script-name +web-root-base+)
-           (string-equal script-name +web-root+)) 'login) ; go to the start page
+           (string-equal script-name +web-root+)) 'root-page) ; go to the start page
       ((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file