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.
SPA Route Fallback
(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 "/"})
(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 ""}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment