Welcome! Please see the About page for a little more info on how this works.

0 votes
in Libs by
edited by

I'm setting up a service that returns a JSON, thanks to Ring, Compojure and Jetty. The problem I have is when I want to use Nginx as a reverse proxy. If I use the following handlers it doesn't work.

(def wrapped-handler
  ;; Handler middlewares
  (-> all-routes
      (wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
      wrap-params
      wrap-session
      ))

The message I get back is

java.lang.NullPointerException
        at ring.adapter.jetty$proxy_handler$fn__6990.invoke(jetty.clj:26)
        at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.eclipse.jetty.server.Server.handle(Server.java:503)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
        at java.base/java.lang.Thread.run(Thread.java:834)

But if I add wrap-reload everything goes right.

(def wrapped-handler
  ;; Handler middlewares
  (-> all-routes
      (wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
      wrap-params
      wrap-session
      (#(if (config :debug) (wrap-reload %)))
      ))

My setup with Nginx is as follows.

server {        

        server_name domain.com;

        location / {
            proxy_pass http://localhost:9000/;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_redirect  off;
        }
}

Is it safe to leave wrap-reload in production?
What have I left behind?

Thank you all in advance.

1 Answer

0 votes
by

It's very hard to tell based on just that information. It's much easier to debug problems like this in an interactive context such as the Clojurians Slack where folks can ask you for additional information and ask you to try things out in real-time.

https://clojurians.slack.com -- self-signup: http://clojurians.net

I would say that you definitely do not want to run wrap-reload in production.

by
The problem was solved, thanks for the advice.

I had the following

(#(if (config :debug) (wrap-reload %)))

Which produced a nil and broke the execution. The solution is

(#(if (config :debug) (wrap-reload %) %))

Or use cond->

(cond-> (config :debug) wrap-reload)))
by
Hmm, I didn't see that conditional in the post when I first looked at it...

cond-> is perfect for this sort of thing (and much easier to read than trying to thread into an anonymous function!).
...