0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00
penpot/exporter/src/app/http.cljs

41 lines
1.1 KiB
Text
Raw Normal View History

;; 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
(ns app.http
(:require
[app.config :as cf]
2020-07-30 08:23:11 -05:00
[app.http.export :refer [export-handler]]
[app.http.export-frames :refer [export-frames-handler]]
2020-07-30 08:23:11 -05:00
[app.http.impl :as impl]
[lambdaisland.glogi :as log]
2020-07-30 08:23:11 -05:00
[promesa.core :as p]
[reitit.core :as r]))
(def routes
[["/export-frames" {:handler export-frames-handler}]
["/export" {:handler export-handler}]])
(def instance (atom nil))
(defn init
[]
2020-07-30 08:23:11 -05:00
(let [router (r/router routes)
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)))
(defn stop
[]
(if-let [server @instance]
(p/create (fn [resolve]
(.close server (fn []
(log/info :msg "shutdown http server")
(resolve)))))
(p/resolved nil)))