From bd70af8e78a97458bbdd828a9ebadfb373399b75 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Fri, 9 Oct 2020 17:28:56 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ deps.edn | 4 ++++ src/openretro/main.clj | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 deps.edn create mode 100644 src/openretro/main.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7307a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +.cpcache diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..e6d9f47 --- /dev/null +++ b/deps.edn @@ -0,0 +1,4 @@ +{:deps + {http-kit/http-kit {:mvn/version "2.3.0"} + metosin/reitit {:mvn/version "0.5.6"} + ring/ring-defaults {:mvn/version "0.3.2"}}} diff --git a/src/openretro/main.clj b/src/openretro/main.clj new file mode 100644 index 0000000..ac8c11f --- /dev/null +++ b/src/openretro/main.clj @@ -0,0 +1,37 @@ +(ns openretro.main + (:require [org.httpkit.server :as http-server] + [reitit.ring :as reitit-ring] + [ring.middleware.defaults :refer [wrap-defaults]])) + +(defn hello [req] + {:status 200 + :headers {"Content-Type" "text/html"} + :body "http-kit"}) + +(defn ws-endpoint [req] + (http-server/with-channel req channel + (http-server/on-close + channel + (fn [status] (println "closed" status))) + (http-server/on-receive + channel + (fn [data] + (http-server/send! channel data))))) + +(def router + (reitit-ring/ring-handler + (reitit-ring/router + [["/hello" {:get {:handler hello}}] + ["/ws" {:get {:handler ws-endpoint}}]]))) + +(defonce server (atom nil)) + +(defn stop-server [] + (when-not (nil? @server) + (@server :timeout 1000) + (reset! server nil))) + +(defn -main [& args] + (reset! server + (http-server/run-server #'router + {:port 8080})))