From b74dfb2ba8bd8991510b6aba3de3ac47e9374bf6 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Sun, 27 Aug 2023 22:12:08 +0200 Subject: feat(backend): Rename routing namespace --- src/backend/tubo/http.clj | 4 ++-- src/backend/tubo/router.clj | 58 --------------------------------------------- src/backend/tubo/routes.clj | 58 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 60 deletions(-) delete mode 100644 src/backend/tubo/router.clj create mode 100644 src/backend/tubo/routes.clj (limited to 'src') diff --git a/src/backend/tubo/http.clj b/src/backend/tubo/http.clj index 9e1359f..2620874 100644 --- a/src/backend/tubo/http.clj +++ b/src/backend/tubo/http.clj @@ -1,7 +1,7 @@ (ns tubo.http (:require [org.httpkit.server :refer [run-server]] - [tubo.router :as router]) + [tubo.routes :as routes]) (:import tubo.DownloaderImpl org.schabi.newpipe.extractor.NewPipe @@ -14,7 +14,7 @@ (start-server! 3000)) ([port] (NewPipe/init (DownloaderImpl/init) (Localization. "en" "GB")) - (reset! server (run-server #'router/app {:port port})) + (reset! server (run-server #'routes/app {:port port})) (println "Server running in port" port))) (defn stop-server! diff --git a/src/backend/tubo/router.clj b/src/backend/tubo/router.clj deleted file mode 100644 index 73e75ee..0000000 --- a/src/backend/tubo/router.clj +++ /dev/null @@ -1,58 +0,0 @@ -(ns tubo.router - (:require - [malli.experimental.lite :as l] - [reitit.ring :as ring] - [reitit.coercion :as coercion] - [reitit.ring.coercion :as rrc] - [reitit.coercion.malli] - [ring.middleware.reload :refer [wrap-reload]] - [ring.middleware.params :refer [wrap-params]] - [ring.middleware.json :refer [wrap-json-response]] - [ring.middleware.cors :refer [wrap-cors]] - [tubo.handler :as handler])) - -(def router - (ring/router - [["/" handler/index] - ["/search" handler/index] - ["/stream" handler/index] - ["/channel" handler/index] - ["/playlist" handler/index] - ["/kiosk" handler/index] - ["/api" - ["/services" - ["" {:get handler/services}] - ["/:service-id/search" - {:get {:coercion reitit.coercion.malli/coercion - :parameters {:path {:service-id int?} - :query {:q string?}} - :handler handler/search}}] - ["/:service-id" - ["/default-kiosk" {:get {:coercion reitit.coercion.malli/coercion - :parameters {:path {:service-id int?}} - :handler handler/kiosk}}] - ["/kiosks" - ["" {:get {:coercion reitit.coercion.malli/coercion - :parameters {:path {:service-id int?}} - :handler handler/kiosks}}] - ["/:kiosk-id" {:get {:coercion reitit.coercion.malli/coercion - :parameters {:path {:service-id int? :kiosk-id string?}} - :handler handler/kiosk}}]]]] - ["/streams/:url" {:get handler/stream}] - ["/channels/:url" {:get handler/channel}] - ["/playlists/:url" {:get handler/playlist}] - ["/comments/:url" {:get handler/comments}]]] - {:data {:middleware [rrc/coerce-request-middleware - rrc/coerce-response-middleware - rrc/coerce-exceptions-middleware]}})) - -(def app - (ring/ring-handler - router - (ring/routes - (ring/create-resource-handler {:path "/"}) - (ring/create-default-handler - {:not-found (constantly {:status 404, :body "Not found"})})) - {:middleware [wrap-params - [wrap-json-response {:pretty true}] - wrap-reload]})) diff --git a/src/backend/tubo/routes.clj b/src/backend/tubo/routes.clj new file mode 100644 index 0000000..d42b432 --- /dev/null +++ b/src/backend/tubo/routes.clj @@ -0,0 +1,58 @@ +(ns tubo.routes + (:require + [malli.experimental.lite :as l] + [reitit.ring :as ring] + [reitit.coercion :as coercion] + [reitit.ring.coercion :as rrc] + [reitit.coercion.malli] + [ring.middleware.reload :refer [wrap-reload]] + [ring.middleware.params :refer [wrap-params]] + [ring.middleware.json :refer [wrap-json-response]] + [ring.middleware.cors :refer [wrap-cors]] + [tubo.handler :as handler])) + +(def router + (ring/router + [["/" handler/index] + ["/search" handler/index] + ["/stream" handler/index] + ["/channel" handler/index] + ["/playlist" handler/index] + ["/kiosk" handler/index] + ["/api" + ["/services" + ["" {:get handler/services}] + ["/:service-id/search" + {:get {:coercion reitit.coercion.malli/coercion + :parameters {:path {:service-id int?} + :query {:q string?}} + :handler handler/search}}] + ["/:service-id" + ["/default-kiosk" {:get {:coercion reitit.coercion.malli/coercion + :parameters {:path {:service-id int?}} + :handler handler/kiosk}}] + ["/kiosks" + ["" {:get {:coercion reitit.coercion.malli/coercion + :parameters {:path {:service-id int?}} + :handler handler/kiosks}}] + ["/:kiosk-id" {:get {:coercion reitit.coercion.malli/coercion + :parameters {:path {:service-id int? :kiosk-id string?}} + :handler handler/kiosk}}]]]] + ["/streams/:url" {:get handler/stream}] + ["/channels/:url" {:get handler/channel}] + ["/playlists/:url" {:get handler/playlist}] + ["/comments/:url" {:get handler/comments}]]] + {:data {:middleware [rrc/coerce-request-middleware + rrc/coerce-response-middleware + rrc/coerce-exceptions-middleware]}})) + +(def app + (ring/ring-handler + router + (ring/routes + (ring/create-resource-handler {:path "/"}) + (ring/create-default-handler + {:not-found (constantly {:status 404, :body "Not found"})})) + {:middleware [wrap-params + [wrap-json-response {:pretty true}] + wrap-reload]})) -- cgit v1.2.3