This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have barista serve up something! yeah.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |