making server buildable

This commit is contained in:
Chris Cochrun 2023-06-13 07:34:00 -05:00
parent bc15f05603
commit ec3bde1191
6 changed files with 85 additions and 17 deletions

16
Makefile Normal file
View file

@ -0,0 +1,16 @@
all: build-server
build-server:
sbcl --eval '(ql:quickload "deploy")' --eval '(asdf:load-asd "/home/chris/dev/tfcconnection/tfcserver.asd")' --eval '(ql:quickload :tfcserver)' --eval '(push :deploy-console *features*)' --eval "(asdf:make :tfcserver)" --eval '(quit)'
serve:
hugo server --noHTTPCache
css:
NODE_ENV=development ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit -w
build-site:
rm -rf public && NODE_ENV=production ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit && hugo --gc --minify
clean:
rm -rf public

View file

@ -2,9 +2,25 @@
stdenv, stdenv,
lib, lib,
hugo, hugo,
go go,
sbcl,
sbclPackages,
makeWrapper,
openssl
}: }:
let
sbcl' = sbcl.withPackages (ps: with ps; [
hunchentoot
dexador
clack
jzon
serapeum
openssl
openssl.out
openssl.dev
]);
in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
name = "tfcconnection"; name = "tfcconnection";
pname = "tfcconnection"; pname = "tfcconnection";
@ -12,16 +28,22 @@ stdenv.mkDerivation rec {
src = ./.; src = ./.;
nativeBuildInputs = [
makeWrapper
];
buildInputs = [ buildInputs = [
hugo hugo
go go
sbcl'
]; ];
buildPhase = '' buildPhase = ''
hugo make
''; '';
installPhase = '' installPhase = ''
''; '';
meta = with lib; { meta = with lib; {

View file

@ -15,6 +15,7 @@
in in
{ {
devShell = import ./shell.nix { inherit pkgs; }; devShell = import ./shell.nix { inherit pkgs; };
defaultPackage = pkgs.callPackage ./default.nix { };
} }
); );
} }

View file

@ -1,14 +1,6 @@
(require :asdf) (ql:quickload '(hunchentoot clack dexador com.inuoe.jzon serapeum bordeaux-threads))
(require :hunchentoot)
(require :dexador)
(require :serapeum)
(require :clack)
(require :com.inuoe.jzon)
;; (load "~/quicklisp/setup.lisp")
;; (ql:quickload :cffi :silent t)
;; (ql:quickload '(hunchentoot clack dexador com.inuoe.jzon serapeum))
(uiop:define-package tfc-server (defpackage tfc-server
(:use :cl :uiop :com.inuoe.jzon :clack)) (:use :cl :uiop :com.inuoe.jzon :clack))
(in-package :tfc-server) (in-package :tfc-server)
@ -19,7 +11,10 @@
(defvar *stream*) (defvar *stream*)
(defvar *auth-token* "boFFRM68vvXbO-DO7S9YDg86lHX027-hd07mn0dh") (defvar *auth-token* "boFFRM68vvXbO-DO7S9YDg86lHX027-hd07mn0dh")
(defvar *server* (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242))) (defvar *server*)
(defun start-server (port)
(setq *server* (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port port))))
(defun post-health-form (data-list) (defun post-health-form (data-list)
"Takes the health form as an alist and posts it to nocodb" "Takes the health form as an alist and posts it to nocodb"
@ -55,9 +50,9 @@
(defun process-form (form) (defun process-form (form)
"Processes the form and sends it on" "Processes the form and sends it on"
(uiop:println "---") (uiop:println "---")
(maphash 'print-hash-entry form) (maphash 'print-hash-entry form)
(uiop:println "---")) (uiop:println "---"))
(defun save-string-file (string file-path) (defun save-string-file (string file-path)
"save a file that is represented as a string to disk that came from a multipart/form-data" "save a file that is represented as a string to disk that came from a multipart/form-data"
@ -86,7 +81,7 @@
(setq *last-list-data* nil) (setq *last-list-data* nil)
(loop :for i :in *last-data* (loop :for i :in *last-data*
:do (let* ((content-disposition (nth 1 :do (let* ((content-disposition (nth 1
(serapeum:lines i :eol-style :crlf :honor-crlf t))) (serapeum:lines i :eol-style :crlf :honor-crlf t)))
(start (if content-disposition (position #\" content-disposition))) (start (if content-disposition (position #\" content-disposition)))
(end (if start (position #\" content-disposition :start (1+ start)) nil)) (end (if start (position #\" content-disposition :start (1+ start)) nil))
(name (if end (if start (subseq content-disposition (1+ start) end) nil) nil)) (name (if end (if start (subseq content-disposition (1+ start) end) nil) nil))
@ -136,3 +131,19 @@
(post-health-form *last-list-data*) (post-health-form *last-list-data*)
(format nil "thankyou")))))) (format nil "thankyou"))))))
(defun main ()
(start-server 4242)
(format t "Server has started on port 4242~&")
(handler-case (bt:join-thread (find-if (lambda (th)
(search "hunchentoot" (bt:thread-name th)))
(bt:all-threads)))
(#+sbcl sb-sys:interactive-interrupt
#+ccl ccl:interrupt-signal-condition
#+clisp system::simple-interrupt-condition
#+ecl ext:interactive-interrupt
#+allegro excl:interrupt-signal
() (progn
(format *error-output* "Aborting.~&")
(hunchentoot:stop *server*)
(uiop:quit)))
(error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 679 KiB

18
tfcserver.asd Normal file
View file

@ -0,0 +1,18 @@
#-asdf3.1 (error "requires asdf 3.1")
(defsystem "tfcserver"
:version "0.1.0"
:author "Chris Cochrun"
:license "AGPLV3"
:depends-on ("hunchentoot" "dexador" "serapeum" "clack" "com.inuoe.jzon" "bordeaux-threads") ;; <== list of Quicklisp dependencies
:components ((:module "src"
:components
((:file "main"))))
:description "Restful server to handle website pieces"
:long-description "Restful server to handle website pieces"
;; :in-order-to ((test-op (test-op "tfcserver-test")))
:defsystem-depends-on (:deploy) ;; (ql:quickload "deploy") before
:build-operation "deploy-op" ;; leave as is
:build-pathname "tfcapi"
:entry-point "tfc-server::main"
)