This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello-ring.core | |
(:require [ring.middleware.file :refer [wrap-file]] | |
[reitit.ring :as ring] | |
[ring.adapter.jetty :refer [run-jetty]]) | |
(:gen-class)) | |
(def handler | |
(ring/ring-handler | |
(ring/router | |
["/math" {:get {:handler (fn [request] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body "Hello World"})}}] | |
{:data {:middleware [#_[wrap-file "."]]}}) ;;; doesn't work here | |
(ring/create-default-handler))) | |
(defn -main | |
[& args] | |
(run-jetty #_handler (wrap-file handler ".") {:port 3000})) ;;; works here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
""""
ikitommi [12:11 AM]
@aaron51 reitit takes route-first approach, where the middleware (defined in router) are only applied if a route is matched. In your example there is only
GET /math
defined - if that doesn’t match, thewrap-file
is not run. Options here are:(wrap-file (ring/create-default-handler) ".")
["/* (wrap-file (constantly nil) ".")]
where the handler always misses (edited)1 is much better, as the
wrap-file
is only run if none of the actual routes match.I think that
wrap-file
always first checks if there is a file available. This mean doing slow IO for ALL calls.""""