-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Extract routes to separate namespace
- Loading branch information
Showing
2 changed files
with
86 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(ns tools.ifs.parts.routes | ||
(:require | ||
[reitit.ring :as ring] | ||
[reitit.swagger :as swagger] | ||
[reitit.swagger-ui :as swagger-ui] | ||
[ring.middleware.json :refer [wrap-json-body wrap-json-response]] | ||
[ring.middleware.params :refer [wrap-params]] | ||
[tools.ifs.parts.api.account :as account] | ||
[tools.ifs.parts.api.auth :as auth] | ||
[tools.ifs.parts.api.middleware :as middleware] | ||
[tools.ifs.parts.pages :as pages] | ||
[tools.ifs.parts.waitlist :as waitlist])) | ||
|
||
(defn prelaunch-app | ||
"Routes for the pre-launch version of the app" | ||
[] | ||
(middleware/wrap-default-middlewares | ||
(ring/ring-handler | ||
(ring/router | ||
[["/" {:get {:handler #(pages/home-page %)}}] | ||
["/waitlist-signup" {:post {:handler #(waitlist/signup %)}}]] | ||
{:data {:middleware [wrap-params | ||
middleware/exception | ||
middleware/logging | ||
middleware/wrap-html-response]}})))) | ||
|
||
;; TODO: We need to later figure out a way to combine HTML routes and API | ||
;; routes. | ||
;; | ||
;; Currently, the main issue is that I cannot figure out a way to combine API | ||
;; namespaces with different sets of middleware for each. | ||
;; | ||
;; For example, I want the /api namespace to have JSON-related middlewares, but | ||
;; not the root namespace, which serves text/html instead. | ||
;; | ||
;; It is also entirely possible that API routes will be removed, and only HTML | ||
;; routes will remain. | ||
(defn app | ||
"Routes for the full application" | ||
[] | ||
(middleware/wrap-default-middlewares | ||
(ring/ring-handler | ||
(ring/router | ||
[["/swagger.json" | ||
{:get {:no-doc true | ||
:swagger {:info {:title "Parts API" | ||
:description "API for Parts"}} | ||
:handler (swagger/create-swagger-handler)}}] | ||
["/api" | ||
["/ping" | ||
{:get {:swagger {:tags ["Utility"]} | ||
:handler (fn [_] {:status 200 :body {:message "Pong!"}})}}] | ||
["/auth" {:swagger {:tags ["Authentication"]}} | ||
["/login" | ||
{:post {:handler auth/login}}] | ||
["/logout" | ||
{:post {:handler auth/logout | ||
:middleware [middleware/jwt-auth]}}]] | ||
["/account" {:swagger {:tags ["Account"]}} | ||
["" | ||
{:get {:handler account/get-account} | ||
:patch {:handler account/update-account} | ||
:delete {:handler account/delete-account} | ||
:middleware [middleware/jwt-auth]}] | ||
["/register" | ||
{:post {:handler account/register-account}}]]] | ||
["/" {:get {:handler #(pages/home-page %)}}]] | ||
{:data {:middleware [wrap-params | ||
middleware/exception | ||
middleware/logging | ||
[wrap-json-body {:keywords? true}] | ||
wrap-json-response | ||
middleware/wrap-jwt-authentication]}}) | ||
(ring/routes | ||
(swagger-ui/create-swagger-ui-handler | ||
{:path "/swagger-ui" | ||
:config {:validatorUrl nil | ||
:operationsSorter "alpha"}}) | ||
(ring/create-default-handler))))) |