Skip to content

Instantly share code, notes, and snippets.

@tmattacchione
Last active September 22, 2021 16:25
Show Gist options
  • Select an option

  • Save tmattacchione/14c6cfa1500bc1ab1a90a98b9d7217a0 to your computer and use it in GitHub Desktop.

Select an option

Save tmattacchione/14c6cfa1500bc1ab1a90a98b9d7217a0 to your computer and use it in GitHub Desktop.

Revisions

  1. tmattacchione revised this gist Aug 12, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@
    ((reitit.ring/ring-handler
    (router)
    (reitit.ring/routes
    (spa-fallback-handler {:path "/"})
    (spa-fallback-handler)
    (reitit.ring/create-default-handler))))))

    (comment
  2. tmattacchione revised this gist Jul 28, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -46,8 +46,15 @@

    (comment

    ;; using option 1
    (app {:request-method :get :uri "/ping"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/"}) ; => {:status 302, :headers {"Location" "/index.html"}, :body ""}
    (app {:request-method :get :uri "/public/index.html"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}

    ;; using option 2
    (app {:request-method :get :uri "/ping"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}
    (app {:request-method :get :uri "/public/index.html"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}
    (app {:request-method :get :uri "/login"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}

    :end)
  3. tmattacchione revised this gist Jul 28, 2020. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    (ns app
    (:require [reitit.ring])
    (:require
    [reitit.ring])
    [ring.util.response :as response]


    (defn secret-route
    @@ -11,13 +13,20 @@
    []
    ["public/*" (reitit.ring/create-resource-handler)])])

    (defn spa-fallback-handler
    []
    (fn [request]
    (or (response/resource-response (:uri request) {:root "public"})
    (-> (response/resource-response "index.html" {:root "public"})
    (response/content-type "text/html")))))

    (defn router []
    (reitit.ring/router
    [(public-resource-route)
    (secret-route)]))


    ;; option 1 - doesn't seem to work
    (defn app [req]
    (-> req
    ((reitit.ring/ring-handler
    @@ -26,6 +35,15 @@
    (reitit.ring/create-resource-handler {:path "/"})
    (reitit.ring/create-default-handler))))))

    ;; option 2 - works
    (defn app [req]
    (-> req
    ((reitit.ring/ring-handler
    (router)
    (reitit.ring/routes
    (spa-fallback-handler {:path "/"})
    (reitit.ring/create-default-handler))))))

    (comment

    (app {:request-method :get :uri "/ping"}) ; => {:status 200, :body "pong"}
  4. tmattacchione revised this gist Jul 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@

    (comment

    (app {:request-method :get :uri "/"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/ping"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/"}) ; => {:status 302, :headers {"Location" "/index.html"}, :body ""}
    (app {:request-method :get :uri "/public/index.html"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}

  5. tmattacchione revised this gist Jul 25, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -30,5 +30,6 @@

    (app {:request-method :get :uri "/"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/"}) ; => {:status 302, :headers {"Location" "/index.html"}, :body ""}
    (app {:request-method :get :uri "/public/index.html"}) ; => {:status 200, :headers {"Content-Length" "667" ... "Content-Type" "text/html"}, :body ..."]}

    )
    :end)
  6. tmattacchione revised this gist Jul 25, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -25,3 +25,10 @@
    (reitit.ring/routes
    (reitit.ring/create-resource-handler {:path "/"})
    (reitit.ring/create-default-handler))))))

    (comment

    (app {:request-method :get :uri "/"}) ; => {:status 200, :body "pong"}
    (app {:request-method :get :uri "/"}) ; => {:status 302, :headers {"Location" "/index.html"}, :body ""}

    )
  7. tmattacchione revised this gist Jul 25, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,5 @@
    ((reitit.ring/ring-handler
    (router)
    (reitit.ring/routes
    (reitit.ring/create-resource-handler {:path "/"}))))))
    (reitit.ring/create-resource-handler {:path "/"})
    (reitit.ring/create-default-handler))))))
  8. tmattacchione created this gist Jul 25, 2020.
    26 changes: 26 additions & 0 deletions reitit-backend-spa.cljs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    (ns app
    (:require [reitit.ring])


    (defn secret-route
    []
    ["/secret" {#_ ...stuff}])


    (defn public-resource-route
    []
    ["public/*" (reitit.ring/create-resource-handler)])])


    (defn router []
    (reitit.ring/router
    [(public-resource-route)
    (secret-route)]))


    (defn app [req]
    (-> req
    ((reitit.ring/ring-handler
    (router)
    (reitit.ring/routes
    (reitit.ring/create-resource-handler {:path "/"}))))))