Created
May 3, 2018 17:28
-
-
Save ddeaguiar/9172555a94d75c749e4a059af6942918 to your computer and use it in GitHub Desktop.
async response sample
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
(ns foo.service | |
(:require [io.pedestal.http :as http] | |
[clojure.core.async :as async] | |
[io.pedestal.http.route :as route] | |
[io.pedestal.interceptor :as i] | |
[io.pedestal.http.body-params :as body-params] | |
[ring.util.response :as ring-resp])) | |
(defn about-page | |
[request] | |
(ring-resp/response (format "Clojure %s - served from %s" | |
(clojure-version) | |
(route/url-for ::about-page)))) | |
(defn home-page | |
[request] | |
(-> (async/go "Hello World!") | |
ring-resp/response | |
(ring-resp/content-type "text/html"))) | |
;; Defines "/" and "/about" routes with their associated :get handlers. | |
;; The interceptors defined after the verb map (e.g., {:get home-page} | |
;; apply to / and its children (/about). | |
(def common-interceptors [(body-params/body-params) http/html-body]) | |
;; Tabular routes | |
(def routes #{["/" :get (conj common-interceptors `home-page)] | |
["/about" :get (conj common-interceptors `about-page)]}) | |
;; Map-based routes | |
;(def routes `{"/" {:interceptors [(body-params/body-params) http/html-body] | |
; :get home-page | |
; "/about" {:get about-page}}}) | |
;; Terse/Vector-based routes | |
;(def routes | |
; `[[["/" {:get home-page} | |
; ^:interceptors [(body-params/body-params) http/html-body] | |
; ["/about" {:get about-page}]]]]) | |
;; Consumed by foo.server/create-server | |
;; See http/default-interceptors for additional options you can configure | |
(def service {:env :prod | |
;; You can bring your own non-default interceptors. Make | |
;; sure you include routing and set it up right for | |
;; dev-mode. If you do, many other keys for configuring | |
;; default interceptors will be ignored. | |
;; ::http/interceptors [] | |
::http/routes routes | |
;; Uncomment next line to enable CORS support, add | |
;; string(s) specifying scheme, host and port for | |
;; allowed source(s): | |
;; | |
;; "http://localhost:8080" | |
;; | |
;;::http/allowed-origins ["scheme://host:port"] | |
;; Tune the Secure Headers | |
;; and specifically the Content Security Policy appropriate to your service/application | |
;; For more information, see: https://content-security-policy.com/ | |
;; See also: https://github.com/pedestal/pedestal/issues/499 | |
;;::http/secure-headers {:content-security-policy-settings {:object-src "'none'" | |
;; :script-src "'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:" | |
;; :frame-ancestors "'none'"}} | |
;; Root for resource interceptor that is available by default. | |
::http/resource-path "/public" | |
;; Either :jetty, :immutant or :tomcat (see comments in project.clj) | |
;; This can also be your own chain provider/server-fn -- http://pedestal.io/reference/architecture-overview#_chain_provider | |
::http/type :immutant | |
;;::http/host "localhost" | |
::http/port 8080 | |
;; Options to pass to the container (Jetty) | |
::http/container-options {:h2c? true | |
:h2? false | |
;:keystore "test/hp/keystore.jks" | |
;:key-password "password" | |
;:ssl-port 8443 | |
:ssl? false}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment