Skip to content

Instantly share code, notes, and snippets.

@dadair-ca
Last active September 18, 2016 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadair-ca/eb0d4bcb5b88e6d1741986a5aad4c93c to your computer and use it in GitHub Desktop.
Save dadair-ca/eb0d4bcb5b88e6d1741986a5aad4c93c to your computer and use it in GitHub Desktop.
--- jwt ---
nil
Starting HTTP server on port nil
{:app
{:middleware
{:functions
{:hide-errors duct.middleware.errors/wrap-hide-errors,
:not-found duct.middleware.not-found/wrap-not-found,
:ring-json-response ring.middleware.json/wrap-json-response,
:ring-json-body ring.middleware.json/wrap-json-body},
:applied
[:ring-json-body :ring-json-response :not-found :hide-errors],
:arguments
{:not-found "Resource Not Found",
:hide-errors "Internal Server Error",
:ring-json-body {:keywords? true, :bigdecimals? true}}}},
:http {:app nil},
:db
{:atom
#<Atom@15324f25:
[{"adair.david@gmail.com"
{:email "adair.david@gmail.com",
:password "secret",
:role "user"}}
{".."
{:email "..",
:password "secret",
:role "admin"}}]>},
:jwt {:secret nil, :opts nil},
:root {:build-routes #'api.endpoint.root/root-endpoint},
:auth {:build-routes #'api.endpoint.auth/auth-endpoint}}
(ns api.component.jwt
(:require [com.stuartsierra.component :as component]
[clojure.pprint]))
(defrecord JWT [secret opts]
component/Lifecycle
(start [this] this)
(stop [this] this))
(defn jwt [config]
(println "--- jwt ---")
(clojure.pprint/pprint config)
(map->JWT config))
(ns api.main
(:gen-class)
(:require [com.stuartsierra.component :as component]
[duct.util.runtime :refer [add-shutdown-hook]]
[duct.util.system :refer [load-system]]
[environ.core :refer [env]]
[clojure.java.io :as io]
[clojure.pprint]))
(defn -main [& args]
(let [system (load-system [(io/resource "api/system.edn")])]
(println "Starting HTTP server on port" (-> system :http :port))
(clojure.pprint/pprint system)
#_(add-shutdown-hook ::stop-system #(component/stop system))
#_(component/start system)))
{:components
{:app duct.component.handler/handler-component
:http ring.component.jetty/jetty-server
:db api.boundary.UsersDatabase/fakedb
:jwt api.component.jwt/jwt}
:endpoints
{:root api.endpoint.root/root-endpoint
:auth api.endpoint.auth/auth-endpoint}
:dependencies
{:http [:app]
:app [:root :auth]
:auth [:db :jwt]}
:config
{:app
{:middleware
{:functions
{:hide-errors duct.middleware.errors/wrap-hide-errors
:not-found duct.middleware.not-found/wrap-not-found
:ring-json-response ring.middleware.json/wrap-json-response
:ring-json-body ring.middleware.json/wrap-json-body}
:applied
[:ring-json-body :ring-json-response
:not-found :hide-errors]
:arguments
{:not-found "Resource Not Found"
:hide-errors "Internal Server Error"
:ring-json-body {:keywords? true :bigdecimals? true}}}}}
:http
{:port 3000}
:jwt
{:secret "jwt-secret-prod"
:opts {:alg :hs512}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment