tfcconnection-zola/src/server/main.lisp

47 lines
1.5 KiB
Common Lisp

(load "~/quicklisp/setup.lisp")
(ql:quickload :hunchentoot)
(ql:quickload :caveman2)
(ql:quickload :jsown)
(ql:quickload :cl-json)
(defpackage tfc-server
(:use #:hunchentoot #:jsown #:caveman2 #:com.inuoe.jzon))
(in-package :tfcconnection)
(defun handle-post-request (request)
(let ((form-data (hunchentoot:req request)))
(with-response-buffer (stream :content-type "text/plain")
(format stream "Received form data: ~A" form-data))))
(push (create-prefix-dispatcher "/data" 'handle-post-request) hunchentoot:*dispatch-table*)
(hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
(setf (hunchentoot:content-type*) "text/plain")
(format nil "Hey~@[ ~A~]!" name))
(hunchentoot:define-easy-handler (respond :uri "/health-form") ()
(setf (hunchentoot:content-type*) "multipart/form-data")
(let ((request-type (hunchentoot:request-method hunchentoot:*request*)))
(cond ((eq request-type :get) nil)
((eq request-type :post)
(let* ((data (hunchentoot:raw-post-data :force-text t))
(json-obj (com.inuoe.jzon:parse data))
)
;; (print (format nil "Json: ~A" (com.inuoe.jzon:stringify json-obj)))
(uiop:println "Received Health Form")
(render-json json-obj)
(process-form json-obj)
data)))))
(defvar *last*)
(defun process-form (form)
"Processes the form and sends it on"
(uiop:println (gethash "yes" form)))
(defun render-json (object)
(uiop:println (format nil "Json: ~A" (com.inuoe.jzon:stringify object))))