Skip to content

Commit

Permalink
prelaunch: Prelaunch routes, switch to hiccup2 ns
Browse files Browse the repository at this point in the history
  • Loading branch information
goshatch committed Sep 30, 2024
1 parent b232f67 commit 03c6b53
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 67 deletions.
97 changes: 60 additions & 37 deletions src/tools/ifs/parts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,81 @@
[tools.ifs.parts.db :as db]
[tools.ifs.parts.pages :as pages]
[tools.ifs.parts.api.auth :as auth]
[tools.ifs.parts.api.account :as account]))
[tools.ifs.parts.api.account :as account]
[tools.ifs.parts.waitlist :as waitlist]))

;; ---------------------------------------------------------
;; Application

(def app
(def prelaunch-app
(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 %)}}]]
[["/" {:get {:handler #(pages/home-page %)}}]
["/waitlist-signup" {:post {:handler #(waitlist/signup %)}}]]
{: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)))))
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.
;;
;; (def app
;; (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)))))

(defn start-server
"Starts the web server"
[port]
(mulog/log ::starting-server :port port)
(server/run-server #'app {:port port}))

(server/run-server #'prelaunch-app {:port port}))

(defn -main
"Entry point into the application via clojure.main -M"
Expand Down
14 changes: 6 additions & 8 deletions src/tools/ifs/parts/layouts/main.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
(ns tools.ifs.parts.layouts.main
(:require [hiccup.page :refer [html5 include-css include-js]]))
(:require [hiccup2.core :refer [html]]))

(defn layout
"Fundamental application layout"
[title & content]
(html5
(html
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
[:meta {:name "description" :content "Toolkit for IFS practitioners and their clients"}]
[:link {:rel "icon" :sizes "192x192" :href "/images/icons/favicon.png"}]
[:link {:rel "apple-touch-icon" :href "/images/icons/favicon.png"}]
[:title title]
(include-css "/css/style.css")
(include-js "/js/main.js")]
[:title (str title " — Parts")]
[:link {:rel "stylesheet" :href "/css/style.css"}]
[:script {:src "/js/main.js"}]]
[:body
[:secton#container content]
[:script
"window.addEventListener('load', function () { tools.ifs.parts.core.init(); });"]]))
[:secton#container content]]))
42 changes: 20 additions & 22 deletions src/tools/ifs/parts/pages.clj
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
(ns tools.ifs.parts.pages
(:require [hiccup.core :refer [html]]
(:require [hiccup2.core :refer [html]]
[tools.ifs.parts.layouts.main :refer [layout]]
[tools.ifs.parts.layouts.partials :refer [header footer]]
[ring.util.response :as response]))

(defn system-graph
"Page rendering the graph of a system"
[system-id]
(-> (response/response
(html
(layout "System"
(header)
[:div
[:h2 "System"]]
[:div#chart]
(footer))))
(response/content-type "text/html")))
(response/response
(html
(layout "System"
(header)
[:div [:h2 "System"]]
[:div#chart]
(footer)))))

(defn home-page
"Page rendered for GET /"
[_]
(-> (response/response
(html
(layout "Home Page"
(header)
[:div#home
[:h1
{:align "center"}
"Understand your client's parts and their relationships"]
[:h3.hook
{:align "center"}
[:strong "Parts"]
" is a tool for IFS practitioners to keep track of, visualise, and explore the relationships between their clients’ parts."]]
(footer))))
(response/content-type "text/html")))
(layout
"Home Page"
(header)
[:div#home
[:h1
{:align "center"}
"Understand your client's parts and their relationships"]
[:h3.hook
{:align "center"}
[:strong "Parts"]
" is a tool for IFS practitioners to keep track of, visualise, and explore the relationships between their clients’ parts."]]
(footer))))))

0 comments on commit 03c6b53

Please sign in to comment.