2021-02-15 06:15:16 -05: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/.
|
|
|
|
;;
|
2021-04-10 02:43:04 -05:00
|
|
|
;; Copyright (c) UXBOX Labs SL
|
2021-02-15 06:15:16 -05:00
|
|
|
|
2020-06-29 09:07:48 -05:00
|
|
|
(ns app.http
|
|
|
|
(:require
|
2021-05-05 02:28:12 -05:00
|
|
|
[app.config :as cf]
|
2020-07-30 08:23:11 -05:00
|
|
|
[app.http.export :refer [export-handler]]
|
2021-08-30 09:54:27 -05:00
|
|
|
[app.http.export-frames :refer [export-frames-handler]]
|
2020-07-30 08:23:11 -05:00
|
|
|
[app.http.impl :as impl]
|
2020-06-29 09:07:48 -05:00
|
|
|
[lambdaisland.glogi :as log]
|
2020-07-30 08:23:11 -05:00
|
|
|
[promesa.core :as p]
|
|
|
|
[reitit.core :as r]))
|
2020-06-29 09:07:48 -05:00
|
|
|
|
|
|
|
(def routes
|
2021-08-30 09:54:27 -05:00
|
|
|
[["/export-frames" {:handler export-frames-handler}]
|
|
|
|
["/export" {:handler export-handler}]])
|
2020-06-29 09:07:48 -05:00
|
|
|
|
2021-05-05 02:28:12 -05:00
|
|
|
(def instance (atom nil))
|
|
|
|
|
|
|
|
(defn init
|
|
|
|
[]
|
2020-07-30 08:23:11 -05:00
|
|
|
(let [router (r/router routes)
|
2021-05-05 02:28:12 -05:00
|
|
|
handler (impl/handler router)
|
|
|
|
server (impl/server handler)
|
|
|
|
port (cf/get :http-server-port 6061)]
|
|
|
|
(.listen server port)
|
|
|
|
(log/info :msg "starting http server" :port port)
|
|
|
|
(reset! instance server)))
|
2020-06-29 09:07:48 -05:00
|
|
|
|
2021-05-05 02:28:12 -05:00
|
|
|
(defn stop
|
|
|
|
[]
|
|
|
|
(if-let [server @instance]
|
|
|
|
(p/create (fn [resolve]
|
|
|
|
(.close server (fn []
|
|
|
|
(log/info :msg "shutdown http server")
|
|
|
|
(resolve)))))
|
|
|
|
(p/resolved nil)))
|