mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
feat(backend): add logout and better router initialization
This commit is contained in:
parent
932875a317
commit
be7e8e63ee
2 changed files with 75 additions and 66 deletions
|
@ -25,6 +25,13 @@
|
|||
(-> (rsp/no-content)
|
||||
(assoc :session {:user-id id})))))))
|
||||
|
||||
(defn logout
|
||||
{:description "User logout endpoint"}
|
||||
[req]
|
||||
(-> (rsp/no-content)
|
||||
(assoc :session nil)
|
||||
(p/resolved)))
|
||||
|
||||
(defn register
|
||||
{:parameters {:body {:username [st/required st/string]
|
||||
:email [st/required st/email]
|
||||
|
|
|
@ -38,89 +38,91 @@
|
|||
:middleware middleware}})
|
||||
|
||||
(def routes
|
||||
(rr/router
|
||||
[["/media/*" (rr/create-resource-handler {:root "public/media"})]
|
||||
["/static/*" (rr/create-resource-handler {:root "public/static"})]
|
||||
[["/media/*" (rr/create-resource-handler {:root "public/media"})]
|
||||
["/static/*" (rr/create-resource-handler {:root "public/static"})]
|
||||
|
||||
["/api/auth"
|
||||
["/login" {:post (handler #'api-auth/login)}]
|
||||
["/register" {:post (handler #'api-auth/register)}]
|
||||
["/recovery/:token" {:get (handler #'api-auth/register)}]
|
||||
["/recovery" {:post (handler #'api-auth/request-recovery)
|
||||
:get (handler #'api-auth/recover-password)}]]
|
||||
["/api/auth"
|
||||
["/login" {:post (handler #'api-auth/login)}]
|
||||
["/logout" {:post (handler #'api-auth/logout)}]
|
||||
["/register" {:post (handler #'api-auth/register)}]
|
||||
["/recovery/:token" {:get (handler #'api-auth/register)}]
|
||||
["/recovery" {:post (handler #'api-auth/request-recovery)
|
||||
:get (handler #'api-auth/recover-password)}]]
|
||||
|
||||
["/api" {:middleware [authorization-middleware]}
|
||||
;; KVStore
|
||||
["/kvstore/:key" {:put (handler #'api-kvstore/upsert)
|
||||
:get (handler #'api-kvstore/retrieve)
|
||||
:delete (handler #'api-kvstore/delete)}]
|
||||
["/api" {:middleware [authorization-middleware]}
|
||||
;; KVStore
|
||||
["/kvstore/:key" {:put (handler #'api-kvstore/upsert)
|
||||
:get (handler #'api-kvstore/retrieve)
|
||||
:delete (handler #'api-kvstore/delete)}]
|
||||
|
||||
["/svg/parse" {:post (handler #'api-svg/parse)}]
|
||||
["/svg/parse" {:post (handler #'api-svg/parse)}]
|
||||
|
||||
;; Projects
|
||||
["/projects" {:get (handler #'api-projects/list-projects)
|
||||
:post (handler #'api-projects/create-project)}]
|
||||
["/projects/by-token/:token" {:get (handler #'api-projects/get-project-by-share-token)}]
|
||||
["/projects/:id" {:put (handler #'api-projects/update-project)
|
||||
:delete (handler #'api-projects/delete-project)}]
|
||||
;; Projects
|
||||
["/projects" {:get (handler #'api-projects/list-projects)
|
||||
:post (handler #'api-projects/create-project)}]
|
||||
["/projects/by-token/:token" {:get (handler #'api-projects/get-project-by-share-token)}]
|
||||
["/projects/:id" {:put (handler #'api-projects/update-project)
|
||||
:delete (handler #'api-projects/delete-project)}]
|
||||
|
||||
;; Pages
|
||||
["/pages" {:get (handler #'api-pages/list-pages)
|
||||
:post (handler #'api-pages/create-page)}]
|
||||
["/pages/:id" {:put (handler #'api-pages/update-page)
|
||||
:delete (handler #'api-pages/delete-page)}]
|
||||
["/pages/:id/metadata" {:put (handler #'api-pages/update-page-metadata)}]
|
||||
["/pages/:id/history" {:get (handler #'api-pages/retrieve-page-history)}]
|
||||
["/pages/:id/history/:hid" {:put (handler #'api-pages/update-page-history)}]
|
||||
;; Pages
|
||||
["/pages" {:get (handler #'api-pages/list-pages)
|
||||
:post (handler #'api-pages/create-page)}]
|
||||
["/pages/:id" {:put (handler #'api-pages/update-page)
|
||||
:delete (handler #'api-pages/delete-page)}]
|
||||
["/pages/:id/metadata" {:put (handler #'api-pages/update-page-metadata)}]
|
||||
["/pages/:id/history" {:get (handler #'api-pages/retrieve-page-history)}]
|
||||
["/pages/:id/history/:hid" {:put (handler #'api-pages/update-page-history)}]
|
||||
|
||||
;; Profile
|
||||
["/profile/me" {:get (handler #'api-users/retrieve-profile)
|
||||
:put (handler #'api-users/update-profile)}]
|
||||
["/profile/me/password" {:put (handler #'api-users/update-password)}]
|
||||
["/profile/me/photo" {:post (handler #'api-users/update-photo)}]
|
||||
;; Profile
|
||||
["/profile"
|
||||
["/me" {:get (handler #'api-users/retrieve-profile)
|
||||
:put (handler #'api-users/update-profile)}]
|
||||
["/me/password" {:put (handler #'api-users/update-password)}]
|
||||
["/me/photo" {:post (handler #'api-users/update-photo)}]]
|
||||
|
||||
;; Library
|
||||
["/library"
|
||||
;; Icons
|
||||
["/icon-collections/:id" {:put (handler #'api-icons/update-collection)
|
||||
:delete (handler #'api-icons/delete-collection)}]
|
||||
["/icon-collections" {:get (handler #'api-icons/list-collections)
|
||||
:post (handler #'api-icons/create-collection)}]
|
||||
;; Library
|
||||
["/library"
|
||||
;; Icons
|
||||
["/icon-collections/:id" {:put (handler #'api-icons/update-collection)
|
||||
:delete (handler #'api-icons/delete-collection)}]
|
||||
["/icon-collections" {:get (handler #'api-icons/list-collections)
|
||||
:post (handler #'api-icons/create-collection)}]
|
||||
|
||||
["/icons/:id/copy" {:put (handler #'api-icons/copy-icon)}]
|
||||
["/icons/:id/copy" {:put (handler #'api-icons/copy-icon)}]
|
||||
|
||||
["/icons/:id" {:put (handler #'api-icons/update-icon)
|
||||
:delete (handler #'api-icons/delete-icon)}]
|
||||
["/icons" {:post (handler #'api-icons/create-icon)
|
||||
:get (handler #'api-icons/list-icons)}]
|
||||
["/icons/:id" {:put (handler #'api-icons/update-icon)
|
||||
:delete (handler #'api-icons/delete-icon)}]
|
||||
["/icons" {:post (handler #'api-icons/create-icon)
|
||||
:get (handler #'api-icons/list-icons)}]
|
||||
|
||||
;; Images
|
||||
["/image-collections/:id" {:put (handler #'api-images/update-collection)
|
||||
:delete (handler #'api-images/delete-collection)}]
|
||||
["/image-collections" {:post (handler #'api-images/create-collection)
|
||||
:get (handler #'api-images/list-collections)}]
|
||||
["/images/:id/copy" {:put (handler #'api-images/copy-image)}]
|
||||
["/images/:id" {:get (handler #'api-images/retrieve-image)
|
||||
:delete (handler #'api-images/delete-image)
|
||||
:put (handler #'api-images/update-image)}]
|
||||
["/images" {:post (handler #'api-images/create-image)
|
||||
:get (handler #'api-images/list-images)}]
|
||||
]
|
||||
;; Images
|
||||
["/image-collections/:id" {:put (handler #'api-images/update-collection)
|
||||
:delete (handler #'api-images/delete-collection)}]
|
||||
["/image-collections" {:post (handler #'api-images/create-collection)
|
||||
:get (handler #'api-images/list-collections)}]
|
||||
["/images/:id/copy" {:put (handler #'api-images/copy-image)}]
|
||||
["/images/:id" {:get (handler #'api-images/retrieve-image)
|
||||
:delete (handler #'api-images/delete-image)
|
||||
:put (handler #'api-images/update-image)}]
|
||||
["/images" {:post (handler #'api-images/create-image)
|
||||
:get (handler #'api-images/list-images)}]
|
||||
]
|
||||
|
||||
]]
|
||||
router-options))
|
||||
]])
|
||||
|
||||
(def app
|
||||
(rr/ring-handler routes (rr/create-default-handler)))
|
||||
|
||||
;; --- State Initialization
|
||||
(def app
|
||||
(delay
|
||||
(-> (rr/router routes router-options)
|
||||
(rr/ring-handler (rr/create-default-handler)))))
|
||||
|
||||
(defn- start-server
|
||||
[config]
|
||||
(jetty/run-jetty app {:join? false
|
||||
:async? true
|
||||
:daemon? true
|
||||
:port (:http-server-port config)}))
|
||||
(jetty/run-jetty @app {:join? false
|
||||
:async? true
|
||||
:daemon? true
|
||||
:port (:http-server-port config)}))
|
||||
|
||||
(defstate server
|
||||
:start (start-server cfg/config)
|
||||
|
|
Loading…
Reference in a new issue