add a lisp server potentially

This commit is contained in:
Chris Cochrun 2023-05-25 14:55:02 -05:00
parent 4242f0d05a
commit 3f6fef03df
5 changed files with 95 additions and 46 deletions

9
src/compile.lisp Normal file
View file

@ -0,0 +1,9 @@
(load "~/quicklisp/setup.lisp")
(ql:quickload :parenscript)
(defpackage tfcconnection
(:use #:ps))
(in-package :tfcconnection)
(with-open-file (ps:*parenscript-stream* #P"~/dev/tfcconnection/static/js/health-form.js" :direction :output :if-exists :supersede) (ps:ps-compile-file #P"~/dev/tfcconnection/src/health-form.lisp"))

View file

@ -1,9 +1,3 @@
;; (load "~/quicklisp/setup.lisp")
;; (ql:quickload :parenscript)
(defpackage tfcconnection
(:use #:ps))
(in-package :tfcconnection)
(defun submit-form ()

46
src/server/main.lisp Normal file
View file

@ -0,0 +1,46 @@
(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))))

File diff suppressed because one or more lines are too long

View file

@ -1,10 +1,10 @@
defpackage(tfcconnection, 'use'(ps));
function submitForm() {
console.log('hello world');
var form13 = document.getElementById('form');
var form5 = document.getElementById('form');
var data = new FormData(form);
__PS_MV_REG = [];
return console.log(form13);
return console.log(form5);
};
function validate(data) {
console.log('validating');