pedestal

mavbozo 2020-10-06T06:01:53.062700Z

@abdullahibra i can reproduce that error with code below. you have to put :route-name before :constraints

(defn respond-hello
  ""
  [request]
  {:status 200 :body "Hello, world"})

(defn greet
  [req] {:status 200 :body "Greet"})

(def routes
  (route/expand-routes
   #{["/hello" :get [respond-hello] :route-name :hello]
     ["/greet/:id" :get [{:name :greet :enter greet}]
      :constraints {:id #"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"}
      :route-name :greet ]})) 

mavbozo 2020-10-06T06:02:39.063100Z

error:

#error {
 :cause "Assert failed: In row 2, there were unused elements (:route-name :greet).\nThe whole route was: [\"/greet/:id\" :get [{:name :greet, :enter #function[mavp.foo/greet]}] :constraints {:id #\"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\"} :route-name :greet]\n(empty? (:remaining ctx))"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "Syntax error macroexpanding at (form-init15957751344353533874.clj:15:3)."
   :data #:clojure.error{:phase :execution, :line 15, :column 3, :source "form-init15957751344353533874.clj"}

abdullahibra 2020-10-06T07:50:26.063500Z

@mavbozo perfect, Thank you 🙂

emccue 2020-10-06T20:04:13.064200Z

So really basic question about servlet interceptors

emccue 2020-10-06T20:04:18.064700Z

say i wanted to add this

emccue 2020-10-06T20:05:07.065200Z

from what i infer from the docs, I would have my service map

emccue 2020-10-06T20:05:42.065900Z

(-> {::http/routes (if (config/production? config)
                         (routes system)
                         (fn [] (routes system)))
         ::http/port (config/server-port config)
         ::http/host (if (config/production? config)
                       "0.0.0.0"
                       "localhost")
         ::http/type :jetty
         ...}
   (add-servlet-filter {:filter DoSFilter}))

emccue 2020-10-06T20:10:14.067Z

is there a way to configure it not via an xml config?

emccue 2020-10-06T20:10:19.067300Z

<filter>
   <filter-name>DoSFilter</filter-name>
   <filter-class>org.eclipse.jetty.servlets.DoSFilter</filter-class>
   <init-param>
     <param-name>maxRequestsPerSec</param-name>
     <param-value>30</param-value>
   </init-param>
 </filter>

2020-10-06T21:14:20.068200Z

@emccue you should be able to configure it in code. Initialize the filter with relevant values then add it