aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tubo/router.clj
blob: 73e75ee0b685b1f5fa97620ece6871e568e9c10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(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]}))