create pedestal hello world
This commit is contained in:
parent
0f3caef7e7
commit
46c6de9491
2 changed files with 20 additions and 62 deletions
26
deps.edn
26
deps.edn
|
|
@ -1,5 +1,9 @@
|
||||||
{:paths ["src"]
|
{:paths ["src"]
|
||||||
:deps {;; http client
|
:deps {;api
|
||||||
|
io.pedestal/pedestal.service {:mvn/version "0.8.0-rc-1"}
|
||||||
|
io.pedestal/pedestal.http-kit {:mvn/version "0.8.0-rc-1"}
|
||||||
|
org.slf4j/slf4j-simple {:mvn/version "2.0.17"}
|
||||||
|
;; http client
|
||||||
clj-http/clj-http {:mvn/version "3.13.1"}
|
clj-http/clj-http {:mvn/version "3.13.1"}
|
||||||
;; logging
|
;; logging
|
||||||
com.taoensso/telemere {:mvn/version "1.0.0"}
|
com.taoensso/telemere {:mvn/version "1.0.0"}
|
||||||
|
|
@ -11,27 +15,9 @@
|
||||||
;; json
|
;; json
|
||||||
cheshire/cheshire {:mvn/version "6.0.0"}
|
cheshire/cheshire {:mvn/version "6.0.0"}
|
||||||
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}
|
org.clojure/clojure {:mvn/version "1.12.1"}}
|
||||||
;; api
|
|
||||||
ring/ring-core {:mvn/version "1.13.0"}
|
|
||||||
ring/ring-jetty-adapter {:mvn/version "1.13.0"}
|
|
||||||
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}
|
|
||||||
metosin/muuntaja {:mvn/version "0.6.11"}
|
|
||||||
metosin/reitit {:mvn/version "0.9.1"}}
|
|
||||||
|
|
||||||
:aliases
|
:aliases
|
||||||
{;; Run with clj -T:build function-in-build
|
{;; Run with clj -T:build function-in-build
|
||||||
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}}
|
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}}
|
||||||
:ns-default build}}}
|
:ns-default build}}}
|
||||||
|
|
||||||
;; :aliases
|
|
||||||
;; {:dev {:extra-deps {com.biffweb/tasks {:git/url "https://github.com/jacobobryant/biff", :git/sha "1570ccc", :git/tag "v1.8.29", :deps/root "libs/tasks"}}
|
|
||||||
;; :extra-paths ["dev" "test"]
|
|
||||||
;; :jvm-opts ["-XX:-OmitStackTraceInFastThrow"
|
|
||||||
;; "-XX:+CrashOnOutOfMemoryError"
|
|
||||||
;; "-Dbiff.env.BIFF_PROFILE=dev"]
|
|
||||||
;; :main-opts ["-m" "com.biffweb.task-runner" "tasks/tasks"]}
|
|
||||||
;; :prod {:jvm-opts ["-XX:-OmitStackTraceInFastThrow"
|
|
||||||
;; "-XX:+CrashOnOutOfMemoryError"
|
|
||||||
;; "-Dbiff.env.BIFF_PROFILE=prod"]
|
|
||||||
;; :main-opts ["-m" "snippets"]}}}
|
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,19 @@
|
||||||
(ns micro-blog.api
|
(ns micro-blog.api
|
||||||
(:require
|
(:require [io.pedestal.connector :as conn]
|
||||||
[ring.adapter.jetty :as jetty]
|
[io.pedestal.http.http-kit :as hk]))
|
||||||
[micro-blog.config :refer [config]]
|
|
||||||
[taoensso.telemere :as tel]
|
|
||||||
[muuntaja.middleware :as mm]
|
|
||||||
[ring.middleware.params]
|
|
||||||
[reitit.ring :as rr]))
|
|
||||||
|
|
||||||
(defn handle-ping [_args]
|
(defn greet-handler [_request]
|
||||||
(tel/log! :info "Got ping request")
|
|
||||||
{:status 200, :body "ok"})
|
|
||||||
|
|
||||||
(defn handle-proc [{params :query-params}]
|
|
||||||
(let [id (get params "id")]
|
|
||||||
(tel/log! {:level :info :data {:id id}} "Got proc request")
|
|
||||||
{:status 200
|
{:status 200
|
||||||
:body :ok}))
|
:body "Hello, world!\n"})
|
||||||
|
|
||||||
(defn wrap [handler id]
|
(def routes
|
||||||
(fn [request]
|
#{["/greet" :get greet-handler :route-name :greet]})
|
||||||
(update (handler request) :wrap (fnil conj '()) id)))
|
|
||||||
|
|
||||||
(def app
|
(defn create-connector []
|
||||||
(rr/ring-handler
|
(-> (conn/default-connector-map 8890)
|
||||||
(rr/router
|
(conn/with-default-interceptors)
|
||||||
["/api" {:middleware [ring.middleware.params/wrap-params
|
(conn/with-routes routes)
|
||||||
mm/wrap-format
|
(hk/create-connector nil)))
|
||||||
[wrap :api]]}
|
|
||||||
["/ping" {:get handle-ping}]
|
|
||||||
["/proc" {:get handle-proc}]])
|
|
||||||
(rr/create-default-handler)))
|
|
||||||
|
|
||||||
(defn run-server []
|
(defn start []
|
||||||
(let [port (@config :api-port)
|
(conn/start! (create-connector)))
|
||||||
host (@config :api-host)]
|
|
||||||
(jetty/run-jetty #'app {:port port :host host})))
|
|
||||||
|
|
||||||
(defn -main []
|
|
||||||
(run-server))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
;; evaluate this def form to start the webapp via the REPL:
|
|
||||||
;; :join? false runs the web server in the background!
|
|
||||||
(def server (jetty/run-jetty #'app {:port 3000 :join? false}))
|
|
||||||
;; evaluate this form to stop the webapp via the the REPL:
|
|
||||||
(.stop server))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue