juxt / bidi

Bidirectional URI routing
MIT License
993 stars 90 forks source link

bidi.ring - alternates don't work #194

Open kwladyka opened 5 years ago

kwladyka commented 5 years ago

Issue #{:get :post} don't work with bidi.ring.

(def route
  ["/" {
        ;"" {:get :main}
        "login" {#{:get :post} :login}
        "consent" {:get :consent}
        true :not-found}])

(def handler
  (bidi/make-handler route resources))

(def app-stateless
  (-> handler
      (wrap-keyword-params {:parse-namespaces? true})
      ;(wrap-restful-format)
      (wrap-params)
      (wrap-resource "public")
      (wrap-content-type)
      (wrap-not-modified)
      #_(add-headers)))

when open login

java.lang.UnsupportedOperationException: count not supported on this type: Keyword
               RT.java:667 clojure.lang.RT.countFrom
               RT.java:639 clojure.lang.RT.count
              core.clj:880 clojure.core/count
              core.clj:874 clojure.core/count
             core.clj:3131 clojure.core/sort-by[fn]
         AFunction.java:51 clojure.lang.AFunction.compare
          TimSort.java:355 java.util.TimSort.countRunAndMakeAscending
          TimSort.java:220 java.util.TimSort.sort
          Arrays.java:1438 java.util.Arrays.sort
             core.clj:3115 clojure.core/sort
             core.clj:3119 clojure.core/sort-by
             core.clj:3119 clojure.core/sort-by
             bidi.cljc:311 bidi.bidi$eval1602$fn__1603.invoke
             bidi.cljc:176 bidi.bidi$eval1468$fn__1469$G__1457__1476.invoke
             bidi.cljc:200 bidi.bidi$match_pair.invokeStatic
             bidi.cljc:194 bidi.bidi$match_pair.invoke
             bidi.cljc:345 bidi.bidi$eval1680$fn__1681$fn__1682.invoke
             core.clj:2701 clojure.core/some
             core.clj:2692 clojure.core/some
             bidi.cljc:345 bidi.bidi$eval1680$fn__1681.invoke
             bidi.cljc:183 bidi.bidi$eval1511$fn__1525$G__1500__1532.invoke
             bidi.cljc:201 bidi.bidi$match_pair.invokeStatic
             bidi.cljc:194 bidi.bidi$match_pair.invoke
             bidi.cljc:345 bidi.bidi$eval1680$fn__1681$fn__1682.invoke
             core.clj:2701 clojure.core/some
             core.clj:2692 clojure.core/some
             bidi.cljc:345 bidi.bidi$eval1680$fn__1681.invoke
             bidi.cljc:183 bidi.bidi$eval1511$fn__1525$G__1500__1532.invoke
             bidi.cljc:201 bidi.bidi$match_pair.invokeStatic
             bidi.cljc:194 bidi.bidi$match_pair.invoke
             bidi.cljc:382 bidi.bidi$match_route_STAR_.invokeStatic
             bidi.cljc:380 bidi.bidi$match_route_STAR_.invoke
              ring.cljc:41 bidi.ring$make_handler$fn__2336.invoke
     keyword_params.clj:53 ring.middleware.keyword-params/wrap-keyword-params[fn]
             params.clj:67 ring.middleware.params/wrap-params[fn]
           resource.clj:25 ring.middleware.resource/wrap-resource-prefer-resources[fn]
       content_type.clj:34 ring.middleware.content-type/wrap-content-type[fn]
       not_modified.clj:61 ring.middleware.not-modified/wrap-not-modified[fn]
         stacktrace.clj:26 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
         stacktrace.clj:96 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
               core.clj:59 ring-debug-logging.core/wrap-with-logger[fn]
      RingHandler.java:115 org.httpkit.server.HttpHandler.run
        Executors.java:511 java.util.concurrent.Executors$RunnableAdapter.call
       FutureTask.java:266 java.util.concurrent.FutureTask.run
ThreadPoolExecutor.java:1149 java.util.concurrent.ThreadPoolExecutor.runWorker
ThreadPoolExecutor.java:624 java.util.concurrent.ThreadPoolExecutor$Worker.run
           Thread.java:748 java.lang.Thread.run

If I change it to:

java.lang.UnsupportedOperationException: nth not supported on this type: PersistentHashSet
                  RT.java:987 clojure.lang.RT.nthFrom
                  RT.java:936 clojure.lang.RT.nth
                bidi.cljc:194 bidi.bidi$match_pair.invokeStatic
                bidi.cljc:194 bidi.bidi$match_pair.invoke
                bidi.cljc:335 bidi.bidi$eval1638$fn__1639$fn__1640.invoke
                core.clj:2701 clojure.core/some
                core.clj:2692 clojure.core/some
                bidi.cljc:335 bidi.bidi$eval1638$fn__1639.invoke
                bidi.cljc:183 bidi.bidi$eval1511$fn__1525$G__1500__1532.invoke
                bidi.cljc:201 bidi.bidi$match_pair.invokeStatic
                bidi.cljc:194 bidi.bidi$match_pair.invoke
                bidi.cljc:345 bidi.bidi$eval1680$fn__1681$fn__1682.invoke
                core.clj:2701 clojure.core/some
                core.clj:2692 clojure.core/some
                bidi.cljc:345 bidi.bidi$eval1680$fn__1681.invoke
                bidi.cljc:183 bidi.bidi$eval1511$fn__1525$G__1500__1532.invoke
                bidi.cljc:201 bidi.bidi$match_pair.invokeStatic
                bidi.cljc:194 bidi.bidi$match_pair.invoke
                bidi.cljc:382 bidi.bidi$match_route_STAR_.invokeStatic
                bidi.cljc:380 bidi.bidi$match_route_STAR_.invoke
                 ring.cljc:41 bidi.ring$make_handler$fn__2336.invoke
        keyword_params.clj:53 ring.middleware.keyword-params/wrap-keyword-params[fn]
                params.clj:67 ring.middleware.params/wrap-params[fn]
              resource.clj:25 ring.middleware.resource/wrap-resource-prefer-resources[fn]
          content_type.clj:34 ring.middleware.content-type/wrap-content-type[fn]
          not_modified.clj:61 ring.middleware.not-modified/wrap-not-modified[fn]
            stacktrace.clj:26 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
            stacktrace.clj:96 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
                  core.clj:59 ring-debug-logging.core/wrap-with-logger[fn]
         RingHandler.java:115 org.httpkit.server.HttpHandler.run
           Executors.java:511 java.util.concurrent.Executors$RunnableAdapter.call
          FutureTask.java:266 java.util.concurrent.FutureTask.run
 ThreadPoolExecutor.java:1149 java.util.concurrent.ThreadPoolExecutor.runWorker
  ThreadPoolExecutor.java:624 java.util.concurrent.ThreadPoolExecutor$Worker.run
              Thread.java:748 java.lang.Thread.run

How to recreate? use #{:get :post} in routes for ring.