Fork me on GitHub
#pedestal
<
2020-10-06
>
mavbozo06:10:53

@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 ]})) 

mavbozo06:10:39

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"}

abdullahibra07:10:26

@mavbozo perfect, Thank you 🙂

emccue20:10:13

So really basic question about servlet interceptors

emccue20:10:18

say i wanted to add this

emccue20:10:07

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

emccue20:10:42

(-> {::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}))

emccue20:10:14

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

emccue20:10:19

<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>

ddeaguiar21:10:20

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