--- /dev/null
+(in-package :empire-web)
+
+(declaim (optimize (space 0) (speed 0) (safety 3) (debug 3)))
+
+
+(defvar *this-file* (load-time-value
+ (or #.*compile-file-pathname* *load-pathname*)))
+
+(defvar *this-dir* (make-pathname :host (pathname-host *this-file*)
+ :device (pathname-device *this-file*)
+ :directory (pathname-directory *this-file*)))
+
+(defparameter +templates-root+ (namestring *this-dir*))
+(defparameter +root-url+ "/eow/static/test.html")
+(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/"))
+
+(defun string-starts-with (string prefix)
+ ;; (from Hunchentoot)
+ (let ((mismatch (mismatch string prefix :test #'char=)))
+ (or (null mismatch)
+ (>= mismatch (length prefix)))))
+
+(defun serve-static ()
+ "Handle a request for a file under static/ directory"
+ (let* ((script-name (script-name))
+ (fname (subseq script-name (length +static-web-root+)))
+ (fullname (concatenate 'string +static-files-root+ fname)))
+ (handle-static-file fullname)))
+
+(defun dispatch (request)
+ (let ((script-name (script-name request)))
+ (cond
+ ((not (string-starts-with script-name +web-root+)) nil) ; do not handle this request
+ ((or (string-equal script-name +web-root-base+)
+ (string-equal script-name +web-root+)) (redirect +root-url+)) ; go to the start page
+ ((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file
+
+
+(defun start ()
+ (pushnew 'dispatch *dispatch-table* :test #'eq))
+