Last active
August 5, 2021 05:14
-
-
Save kno3comma14/7578afbc93ab07ff3d4a7e22b7e1c524 to your computer and use it in GitHub Desktop.
Adding middleware to duct apis
This file contains hidden or 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
| ....... | |
| :todo-api.middleware/wrap-cors | |
| {:access-control-allow-origin [#todo-api/regex ".*"] | |
| :access-control-allow-methods [:get :put :post :delete]} | |
| :duct.handler/root | |
| {:middleware [#ig/ref :todo-api.middleware/wrap-cors]} | |
| ........ |
This file contains hidden or 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
| ;; dev/src/dev.clj | |
| (ns dev | |
| (:refer-clojure :exclude [test]) | |
| (:require [clojure.repl :refer :all] | |
| [fipp.edn :refer [pprint]] | |
| [clojure.tools.namespace.repl :refer [refresh]] | |
| [clojure.java.io :as io] | |
| [duct.core :as duct] | |
| [duct.core.repl :as duct-repl] | |
| [eftest.runner :as eftest] | |
| [integrant.core :as ig] | |
| [integrant.repl :refer [clear halt go init prep]] | |
| [integrant.repl.state :refer [config system]] | |
| [ragtime.jdbc] | |
| [ragtime.repl] | |
| [orchestra.spec.test :as stest] | |
| [todo-api.main :refer [custom-readers]])) ;;this | |
| (duct/load-hierarchy) | |
| (defn read-config [] | |
| (duct/read-config (io/resource "todo_api/config.edn") | |
| custom-readers)) ;;this |
This file contains hidden or 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 todo-api.main | |
| (:gen-class) | |
| (:require [duct.core :as duct])) | |
| (duct/load-hierarchy) | |
| (def custom-readers ;; this | |
| {'todo-api/regex re-pattern}) ;; this | |
| (defn -main [& args] | |
| (let [keys (or (duct/parse-keys args) [:duct/daemon]) | |
| profiles [:duct.profile/prod]] | |
| (-> (duct/resource "todo_api/config.edn") | |
| (duct/read-config custom-readers) ;;this | |
| (duct/exec-config profiles keys)))) |
This file contains hidden or 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 todo-api.middleware | |
| (:require [integrant.core :as ig] | |
| [ring.middleware.cors :refer [wrap-cors]])) | |
| (defmethod ig/init-key ::wrap-cors [_ config] | |
| #(apply wrap-cors % (apply concat config))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment