You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
(ns blog.server
|
|
(:require ["express" :as express]
|
|
["express-handlebars" :refer [engine]]
|
|
[blog.db :as db]
|
|
[blog.env :as env]
|
|
[blog.handlers :as handlers]))
|
|
|
|
(def app (express))
|
|
(def port (env/get-port))
|
|
(def client (db/create-client))
|
|
|
|
(defn setup-engine
|
|
"Sets the engine to handlebars and simple set up."
|
|
[]
|
|
|
|
; For using .hbs as the file extension instead of .handlebars
|
|
(. app
|
|
engine ".hbs" (engine (-> {:extname ".hbs"
|
|
:defaultLayout "main"}
|
|
(cljs.core/clj->js))))
|
|
|
|
(. app
|
|
set "view engine" ".hbs")
|
|
|
|
(. app
|
|
set "views" "./views"))
|
|
|
|
(defn set-routes
|
|
"Sets the routes for server."
|
|
[]
|
|
(. app get "/"
|
|
(handlers/index-page-handler-factory client))
|
|
(fn [req res]
|
|
|
|
(. app get "/admin"
|
|
(handlers/admin-panel-handler-factory client))
|
|
|
|
(. app get "/htmx/articles/:id"
|
|
(handlers/htmx-get-article-handler-factory client))
|
|
|
|
(. app get "/htmx/admin/rows/article/:id/"
|
|
(handlers/htmx-get-article-row-handler-factory client))
|
|
|
|
(. app get "/htmx/admin/modals/article/content/:id/"
|
|
(handlers/htmx-get-article-preview-content-handler-factory client))
|
|
)
|
|
|
|
(defn start
|
|
"Starts server."
|
|
[]
|
|
(setup-engine)
|
|
(set-routes)
|
|
|
|
(db/connect-client client)
|
|
|
|
(. app listen port
|
|
(fn []
|
|
(println "Listen on " port))))
|
|
|