initial commit

master
Josha von Gizycki 4 years ago
parent 7e1895c5ee
commit bd70af8e78

2
.gitignore vendored

@ -0,0 +1,2 @@
*~
.cpcache

@ -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"}}}

@ -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})))
Loading…
Cancel
Save