Skip to content

Instantly share code, notes, and snippets.

@BilalQadri
Created January 22, 2018 16:11
Show Gist options
  • Save BilalQadri/b063b950a7e37d9429de11d2802ed275 to your computer and use it in GitHub Desktop.
Save BilalQadri/b063b950a7e37d9429de11d2802ed275 to your computer and use it in GitHub Desktop.
Hunchentoot starting point (routing)
;;; hunchentoot and split-sequence are required (hint: via quicklisp)
(defvar acceptor nil)
(setf *default-pathname-defaults* #p"~/code/lisp/attend/maker/")
(setf acceptor (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242)))
;;(hunchentoot:stop acceptor)
(push (create-folder-dispatcher-and-handler "/static/" #p"~/code/lisp/attend/maker/public/")
*dispatch-table*) ;; serve static content (css,js etc)
(push (create-static-file-dispatcher-and-handler "/" #p"~/code/lisp/attend/maker/index.html")
*dispatch-table*) ;; main file
(push (create-prefix-dispatcher "/req/" 'get-req) *dispatch-table*) ;;; all requests under "/req/" to 'get-req function
;;; now these methods will act like POST
(push :PUT *methods-for-post-parameters*)
(push :DELETE *methods-for-post-parameters*)
(defun get-req () ;; e.g http://localhost/req/sth/ ---> sth
(let ((action (split-uri (request-uri*))))
action))
(defun split-uri (uri)
(let* ((uri (string-left-trim "/" (string-right-trim "/" uri)))
(split (split-sequence #\/ uri)))
(cadr split)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment