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: com/mefesto/myapp/web | |
(defn get-profile [{params :params :as request}] | |
(let [res (profile/find-by-id (:id params))] | |
(json-response res))) | |
(defn get-attachment [{params :params :as request}] | |
(let [attachment-dir (get-in request [:myapp :config :attachment-dir])] | |
(file-response (hash->file attachment-dir (:hash params))))) | |
;; assemble routes | |
; (def app ...) | |
;;; ns: com/mefesto/myapp/middleware | |
(defn wrap-context-config [handler config] | |
(fn [request] | |
(handler (assoc-in request [:myapp :config] config)))) | |
(defn wrap-db-connection [handler config] | |
(let [ds (doto (BasicDataSource.) | |
(.setDriverClassName (:driver-class-name config)) | |
(.setUrl (:url config)) | |
(.setUsername (:username config)) | |
(.setPassword (:password config)))] | |
(fn [request] | |
(sql/with-connection {:datasource ds} | |
(handler request))))) | |
;;; ns: com/mefesto/myapp/server | |
(defn -main [& args] | |
(let [config (read-config (first args))] | |
(run-jetty (-> web/app | |
(wrap-db-connection config) | |
(wrap-context-config config)) | |
{:port {:port config}}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment