Skip to content

Instantly share code, notes, and snippets.

@mefesto

mefesto/ex1.clj Secret

Created January 21, 2011 21:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mefesto/8cea49536a6288ee4d7e to your computer and use it in GitHub Desktop.
;;; 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