Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
First attempt at using lanes, ouch that was a lot of time.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmealing committed Oct 29, 2023
1 parent fbd3ce5 commit daa6331
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 42 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ $ rebar3 as test lfe test

## Usage [↟](#table-of-contents)


```shell
$ rebar3 lfe run
```

```shell
$ podman load --input image.tar
$ podman run whatever
```

## Roadmap [↟](#roadmap)

Expand All @@ -93,6 +98,8 @@ $ rebar3 lfe run

☑ Provide an example of serving htmx from LFE.

☐ Use Lanes as the router (less hassle than current)

☑ - Add github actions for quick test results.

☐ Add github action to create container
Expand Down
10 changes: 5 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{erl_opts, [{src_dirs, ["src", "test"]}]}.

{deps, [
{lfe, "2.1.2"},
{ltest, "0.13.5"},
{barista, "0.3.4"},
{lanes, "0.3.3"},
{lanes_barista, "0.3.3"},
{barista, "0.3.2"},
{logjam, "1.2.2"},
{lanes, "0.3.0-rc4"},
{lanes_barista, "0.3.0-rc4"},
{proper, "1.4.0"}

]}.

{plugins, [
Expand Down
4 changes: 3 additions & 1 deletion scripts/main.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
(defun main (args)
(let ((script-name (escript:script_name)))
(io:format "Running script '~s' with args ~p ...~n" `(,script-name ,args))
(io:format "~p~n" `(,(untitled_project:start)))))
(io:format "~p~n" `(,(untitled_project:start))))
(timer:sleep 30000000)
)
98 changes: 63 additions & 35 deletions src/barista-routes.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
(export (do 1)
(handle 3)))

(include-lib "include/macros.lfe")
(include-lib "logjam/include/logjam.hrl")

(defun do (httpd-req)
(let ((req (barista-request:->map httpd-req)))
Expand All @@ -15,41 +17,67 @@
"Cache-Control: no-store"
"\r\n"))

(defun handle
(('GET (list (binary ("chapter1"))) (= `#m(body ,body) req))
(progn
(lfe_io:format "Serving up get on chapter 1~n" '())
(let* ((headers (generate-headers))
(body (list (template:load "chapter1.html"))))
(lfe_io:format "headers: ~p~n" `(,headers))
(barista:response 200 headers body))))

(('GET (list (binary ("chapter2"))) (= `#m(body ,body) req))
(progn
(lfe_io:format "Serving up get on chapter 2~n" '())
(let* ((headers (generate-headers))
(body (list (template:load "chapter2.html"))))
(lfe_io:format "headers: ~p~n" `(,headers))
(barista:response 200 headers body))))

(('POST (list (binary ("chapter1-clicked")) )(= `#m(body ,body) req))
(progn
(let* ((headers (generate-headers))
(body (list (binary "<b> This is just a html fragment </b>"))))
(lfe_io:format "headers: ~p~n" `(,headers))
(barista:response 200 headers body))))

;; catch all, i guess.
((method path (= `#m(body ,body) req))
(progn
(lfe_io:format "METHOD IS ATOM?: ~p~n" (list (is_atom method)))
(lfe_io:format "method: ~p~n" (list method))
(lfe_io:format "catch all~n" '())
(lfe_io:format "path: ~p~n" (list path))
(let* ((headers (generate-headers))
(body (list (template:load "index.html"))))
(lfe_io:format "headers: ~p~n" `(,headers))
(barista:response 200 headers body)))))

(defroutes
;; This macro generates the handle/3 function used by do/1.
;;
;; top-level
('GET #"/"
(progn
(logger:debug "This is getting old, why doesnt this match ")
(barista-response:ok (erlang:binary_to_list (template:load "index.html")))))

;; single order operations
('POST #"/order"
(progn
(barista-response:ok "ORDER PLACED")))

('GET #"/test/"
(barista-response:ok "sure fine whatever"))

;; error conditions
('ALLOWONLY ('GET 'POST 'PUT 'DELETE)
(barista-response:method-not-allowed))
('NOTFOUND
(progn
(logger:info "Bad path probably.. ?")
(barista-response:not-found "Bad path!: invalid operation."))))

;; (defun handle
;; (('GET (list (binary ("chapter1"))) (= `#m(body ,body) req))
;; (progn
;; (lfe_io:format "Serving up get on chapter 1~n" '())
;; (let* ((headers (generate-headers))
;; (body (list (template:load "chapter1.html"))))
;; (lfe_io:format "headers: ~p~n" `(,headers))
;; (barista:response 200 headers body)))))

;; (('GET (list (binary ("chapter2"))) (= `#m(body ,body) req))
;; (progn
;; (lfe_io:format "Serving up get on chapter 2~n" '())
;; (let* ((headers (generate-headers))
;; (body (list (template:load "chapter2.html"))))
;; (lfe_io:format "headers: ~p~n" `(,headers))
;; (barista:response 200 headers body))))

;; (('POST (list (binary ("chapter1-clicked")) )(= `#m(body ,body) req))
;; (progn
;; (let* ((headers (generate-headers))
;; (body (list (binary "<b> This is just a html fragment </b>"))))
;; (lfe_io:format "headers: ~p~n" `(,headers))
;; (barista:response 200 headers body))))

;; ;; catch all, i guess.
;; ((method path (= `#m(body ,body) req))
;; (progn
;; (lfe_io:format "METHOD IS ATOM?: ~p~n" (list (is_atom method)))
;; (lfe_io:format "method: ~p~n" (list method))
;; (lfe_io:format "catch all~n" '())
;; (lfe_io:format "path: ~p~n" (list path))
;; (let* ((headers (generate-headers))
;; (body (list (template:load "index.html"))))
;; (lfe_io:format "headers: ~p~n" `(,headers))
;; (barista:response 200 headers body)))))



Expand Down
8 changes: 7 additions & 1 deletion src/barista-server-app.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
(behaviour application)
(export all))


(include-lib "logjam/include/logjam.hrl")


(defun config ()
'(#(port 8888)
#(server_name "barista-server-app")
#(modules (barista-routes))))

(defun start ()
(logger:set_primary_config #m(level all))
(logjam:set-config `#(path ,"config/sys.config"))
(logger:alert "Starting barista server: ")
(barista:start (config))
;; (: timer sleep 'infinity)
)

(defun start (_type _args)
Expand Down

0 comments on commit daa6331

Please sign in to comment.