2021-02-15 12:15:16 +01:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
|
|
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
;; defined by the Mozilla Public License, v. 2.0.
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
|
|
|
|
2020-06-29 16:07:48 +02:00
|
|
|
(ns app.http
|
|
|
|
(:require
|
2020-07-30 15:23:11 +02:00
|
|
|
[app.http.export :refer [export-handler]]
|
2020-09-07 10:56:42 +02:00
|
|
|
[app.http.thumbnail :refer [thumbnail-handler]]
|
2020-07-30 15:23:11 +02:00
|
|
|
[app.http.impl :as impl]
|
2020-06-29 16:07:48 +02:00
|
|
|
[lambdaisland.glogi :as log]
|
2020-07-30 15:23:11 +02:00
|
|
|
[promesa.core :as p]
|
|
|
|
[reitit.core :as r]))
|
2020-06-29 16:07:48 +02:00
|
|
|
|
|
|
|
(def routes
|
2020-09-07 10:56:42 +02:00
|
|
|
[["/export/thumbnail" {:handler thumbnail-handler}]
|
|
|
|
["/export" {:handler export-handler}]])
|
2020-06-29 16:07:48 +02:00
|
|
|
|
|
|
|
(defn start!
|
|
|
|
[extra]
|
|
|
|
(log/info :msg "starting http server" :port 6061)
|
2020-07-30 15:23:11 +02:00
|
|
|
(let [router (r/router routes)
|
|
|
|
handler (impl/handler router extra)
|
|
|
|
server (impl/server handler)]
|
2020-06-29 16:07:48 +02:00
|
|
|
(.listen server 6061)
|
|
|
|
(p/resolved server)))
|
|
|
|
|
|
|
|
(defn stop!
|
|
|
|
[server]
|
|
|
|
(p/create (fn [resolve]
|
|
|
|
(.close server (fn []
|
|
|
|
(log/info :msg "shutdown http server")
|
|
|
|
(resolve))))))
|