diff --git a/src/barista-routes.lfe b/src/barista-routes.lfe new file mode 100644 index 0000000..5bd1cff --- /dev/null +++ b/src/barista-routes.lfe @@ -0,0 +1,27 @@ +(defmodule barista-routes + (export + (do 1) + (handle 3))) + + +(defun do (httpd-req) + (let ((req (barista-request:->map httpd-req))) + (handle (list_to_atom (mref req 'method)) + (mref req 'path) + req))) + + +(defun handle + ((method path (= `#m(body ,body) req)) + "Example handler that displays whatever is passed through." + (lfe_io:format "method: ~p~n" (list method)) + (lfe_io:format "path: ~p~n" (list path)) + (let* ((headers '("Content-Type: text/plain" + "Cache-Control: no-cache" + "Cache-Control: no-store" + "\r\n")) + (body "hey there!\r\n")) + (lfe_io:format "headers: ~p~n" `(,headers)) + (lfe_io:format "body: ~p~n~n" `(,body)) + (barista:response 200 headers body)))) + diff --git a/src/barista-server-app.lfe b/src/barista-server-app.lfe new file mode 100644 index 0000000..7bcb702 --- /dev/null +++ b/src/barista-server-app.lfe @@ -0,0 +1,25 @@ +(defmodule barista-server-app + (behaviour application) + (export all)) + +(defun config () + '(#(port 5098) + #(server_name "barista-server-app") + #(modules (barista-routes)))) + +(defun start () + (barista:start (config)) + (: timer sleep 'infinity) + ) + +(defun start (_type _args) + (start)) + +(defun stop (pid) + (barista:stop pid)) + +(defun stop () + (inets:stop 'httpd)) + +(defun main (args) + (start))