weavejester / lein-ring

Ring plugin for Leiningen
Eclipse Public License 1.0
501 stars 100 forks source link

Problem passing jetty adapter options as :adapter map using ring by server-headless #206

Open erkkikeranen opened 5 years ago

erkkikeranen commented 5 years ago

According to the README you can provide the following as general options to project.clj:

:adapter - A map of options to be passed to the Ring adapter. This has no effect if you're deploying your application as a war-file.

Here's my project.clj

:ring {
  :handler myapp.states.ring/ap
  :adapter {:configurator (ring-jetty-ws.ws/configurator myapp.handlers.ws/ws-handler)}
  :init myapp.core/setup
  :destroy myapp.core/teardown
  :port 3000
  :nrepl {:start? true :port 7000}}

When running with the command lein ring server-headless, jetty starts but doesn't run the configurator so I can't get websocket endpoints/servlets running.

In the compiled artifact everything works when jetty is started as follows:

(run-jetty myapp.states.ring/app
  {:port 3000
   :join? true
   :configurator (ring-jetty-ws.ws/configurator myapp.handlers.ws/ws-handler)})

Maybe I've misunderstood something from the documentation how the :adapter map is supposed to work? Is this working as intended?

erkkikeranen commented 5 years ago

some progress (might be that I had a mess in my project or dependencies):

Now it seems to have an effect of having the :adapter map because including it causes:

Exception in thread "main" Syntax error compiling at (/private/var/folders/0y/g6kx6w112zndgv908np1skg43swtbm/T/form-init11360811749677766763.clj:1:126).
    at clojure.lang.Compiler.load(Compiler.java:7647)
    at clojure.lang.Compiler.loadFile(Compiler.java:7573)
    at clojure.main$load_script.invokeStatic(main.clj:452)
    at clojure.main$init_opt.invokeStatic(main.clj:454)
    at clojure.main$init_opt.invoke(main.clj:454)
    at clojure.main$initialize.invokeStatic(main.clj:485)
    at clojure.main$null_opt.invokeStatic(main.clj:519)
    at clojure.main$null_opt.invoke(main.clj:516)
    at clojure.main$main.invokeStatic(main.clj:598)
    at clojure.main$main.doInvoke(main.clj:561)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Var.applyTo(Var.java:705)
    at clojure.main.main(main.java:37)
Caused by: java.lang.ClassCastException: class clojure.lang.PersistentList cannot be cast to class clojure.lang.IFn (clojure.lang.PersistentList and clojure.lang.IFn are in unnamed module of loader 'app')
    at ring.adapter.jetty$run_jetty.invokeStatic(jetty.clj:169)
    at ring.adapter.jetty$run_jetty.invoke(jetty.clj:127)
    at ring.server.standalone$serve$fn__4182.invoke(standalone.clj:103)
    at ring.server.standalone$try_port.invokeStatic(standalone.clj:15)
    at ring.server.standalone$try_port.invoke(standalone.clj:10)
    at ring.server.standalone$serve.invokeStatic(standalone.clj:100)
    at ring.server.standalone$serve.doInvoke(standalone.clj:75)
    at clojure.lang.RestFn.invoke(RestFn.java:423)
    at ring.server.leiningen$serve.invokeStatic(leiningen.clj:19)
    at ring.server.leiningen$serve.invoke(leiningen.clj:16)
    at user$eval37688.invokeStatic(form-init11360811749677766763.clj:1)
    at user$eval37688.invoke(form-init11360811749677766763.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:7176)
    at clojure.lang.Compiler.eval(Compiler.java:7166)
    at clojure.lang.Compiler.eval(Compiler.java:7166)
    at clojure.lang.Compiler.load(Compiler.java:7635)
    ... 12 more

Commenting it starts the jetty, but of course does not include websockets.

weavejester commented 5 years ago

The data from the :adapter key is just passed verbatim to the adapter. Lein-Ring doesn't currently do anything to evaluate lists or symbols, or require the relevant namespaces.