mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31:11 +00:00
wip
This commit is contained in:
parent
07acbb275f
commit
9ca63b545b
1 changed files with 28 additions and 17 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
(ns example.server
|
(ns example.server
|
||||||
(:require [io.pedestal.http :as http]
|
(:require [io.pedestal.http]
|
||||||
|
[clojure.core.async :as a]
|
||||||
[reitit.pedestal :as pedestal]
|
[reitit.pedestal :as pedestal]
|
||||||
[reitit.http :as reitit-http]
|
[reitit.http :as http]
|
||||||
[reitit.ring :as ring]))
|
[reitit.ring :as ring]))
|
||||||
|
|
||||||
(defn interceptor [x]
|
(defn interceptor [x]
|
||||||
|
|
@ -10,18 +11,27 @@
|
||||||
|
|
||||||
(def routing-interceptor
|
(def routing-interceptor
|
||||||
(pedestal/routing-interceptor
|
(pedestal/routing-interceptor
|
||||||
(reitit-http/router
|
(http/router
|
||||||
["/api"
|
["/api"
|
||||||
{:interceptors [[interceptor :api]
|
{:interceptors [[interceptor :api]
|
||||||
[interceptor :apa]]}
|
[interceptor :apa]]}
|
||||||
|
|
||||||
["/ping"
|
["/sync"
|
||||||
{:interceptors [[interceptor :ping]]
|
{:interceptors [[interceptor :sync]]
|
||||||
:get {:interceptors [[interceptor :get]]
|
:get {:interceptors [[interceptor :get]]
|
||||||
:handler (fn [_]
|
:handler (fn [_]
|
||||||
(println "handler")
|
(println "handler")
|
||||||
{:status 200,
|
{:status 200,
|
||||||
:body "pong"})}}]]
|
:body "pong"})}}]
|
||||||
|
|
||||||
|
["/async"
|
||||||
|
{:interceptors [[interceptor :async]]
|
||||||
|
:get {:interceptors [[interceptor :get]]
|
||||||
|
:handler (fn [_]
|
||||||
|
(a/go
|
||||||
|
(println "handler")
|
||||||
|
{:status 200,
|
||||||
|
:body "pong"}))}}]]
|
||||||
{:data {:interceptors [[interceptor :router]]}})
|
{:data {:interceptors [[interceptor :router]]}})
|
||||||
(ring/create-default-handler)
|
(ring/create-default-handler)
|
||||||
{:interceptors [[interceptor :top]]}))
|
{:interceptors [[interceptor :top]]}))
|
||||||
|
|
@ -30,21 +40,22 @@
|
||||||
|
|
||||||
(defn start []
|
(defn start []
|
||||||
(when @server
|
(when @server
|
||||||
(http/stop @server)
|
(io.pedestal.http/stop @server)
|
||||||
(println "server stopped"))
|
(println "server stopped"))
|
||||||
(-> {:env :prod
|
(-> {:env :prod
|
||||||
::http/routes []
|
:io.pedestal.http/routes []
|
||||||
::http/resource-path "/public"
|
:io.pedestal.http/resource-path "/public"
|
||||||
::http/type :jetty
|
:io.pedestal.http/type :jetty
|
||||||
::http/port 3000}
|
:io.pedestal.http/port 3000}
|
||||||
(merge {:env :dev
|
(merge {:env :dev
|
||||||
::http/join? false
|
:io.pedestal.http/join? false
|
||||||
::http/allowed-origins {:creds true :allowed-origins (constantly true)}})
|
:io.pedestal.http/allowed-origins {:creds true :allowed-origins (constantly true)}})
|
||||||
(pedestal/default-interceptors routing-interceptor)
|
(pedestal/default-interceptors routing-interceptor)
|
||||||
http/dev-interceptors
|
io.pedestal.http/dev-interceptors
|
||||||
http/create-server
|
io.pedestal.http/create-server
|
||||||
http/start
|
io.pedestal.http/start
|
||||||
(->> (reset! server)))
|
(->> (reset! server)))
|
||||||
(println "server running in port 3000"))
|
(println "server running in port 3000"))
|
||||||
|
|
||||||
(start)
|
(comment
|
||||||
|
(start))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue