I'm using ring-json to deliver json data to a front end that uses reagent to render some d3 charts. I've had the simple project working locally, but when I deployed it to heroku I got the following errors (from the heroku log):
2016-08-01T15:50:38.955857+00:00 app[web.1]: java.lang.Exception: Unrecognized body: [{:key "GB", :values [{:y 2.4555984, :x 2002} {:y 2.519768, :x 2004} {:y 2.4532163, :x 2006} {:y 2.420068, :x 2008} {:y 2.464492, :x 2010} {:y 2.321085, :x 2012}]} {:key "ES", :values [{:y 2.2434933, :x 2002} {:y 2.34095, :x 2004} {:y 2.1764393, :x 2006} {:y 2.0458074, :x 2008} {:y 2.1055703, :x 2010} {:y 2.041821, :x 2012}]} {:key "DE", :values [{:y 2.3088598, :x 2002} {:y 2.3240418, :x 2004} {:y 2.414952, :x 2006} {:y 2.2453654, :x 2008} {:y 2.2269878, :x 2010} {:y 2.1301556, :x 2012}]} {:key "FR", :values [{:y 2.292432, :x 2002} {:y 2.6937985, :x 2004} {:y 2.2779455, :x 2006} {:y 2.3077664, :x 2008} {:y 2.390625, :x 2010} {:y 2.3109756, :x 2012}]} {:key "HU", :values [{:y 2.5220544, :x 2002} {:y 2.570761, :x 2004} {:y 2.7397892, :x 2006} {:y 3.0420985, :x 2008} {:y 2.8456118, :x 2010} {:y 2.5978153, :x 2012}]} {:key "FI", :values [{:y 2.3738055, :x 2002} {:y 2.4264107, :x 2004} {:y 3.1687763, :x 2006} {:y 3.2200456, :x 2008} {:y 3.2385516, :x 2010} {:y 2.240783, :x 2012}]} {:key "PT", :values [{:y 2.8570483, :x 2002} {:y 2.8615985, :x 2004} {:y 2.649865, :x 2006} {:y 2.7748206, :x 2008} {:y 2.8316278, :x 2010} {:y 2.8707578, :x 2012}]} {:key "SE", :values [{:y 2.7565827, :x 2002} {:y 2.7382352, :x 2004} {:y 3.7057602, :x 2006} {:y 3.5786886, :x 2008} {:y 2.478958, :x 2010} {:y 2.2799134, :x 2012}]}]
2016-08-01T15:50:38.955860+00:00 app[web.1]: at ring.util.servlet$update_servlet_response.invokeStatic(servlet.clj:115)
2016-08-01T15:50:38.955859+00:00 app[web.1]: at ring.util.servlet$set_body.invoke(servlet.clj:84)
2016-08-01T15:50:38.955861+00:00 app[web.1]: at ring.adapter.jetty$proxy_handler$fn__3274.invoke(jetty.clj:26)
2016-08-01T15:50:38.955861+00:00 app[web.1]: at ring.util.servlet$update_servlet_response.invoke(servlet.clj:107)
2016-08-01T15:50:38.955863+00:00 app[web.1]: at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
2016-08-01T15:50:38.955865+00:00 app[web.1]: at org.eclipse.jetty.server.Server.handle(Server.java:497)
2016-08-01T15:50:38.955858+00:00 app[web.1]: at ring.util.servlet$set_body.invokeStatic(servlet.clj:105)
2016-08-01T15:50:38.955864+00:00 app[web.1]: at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
2016-08-01T15:50:38.955867+00:00 app[web.1]: at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
2016-08-01T15:50:38.955869+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745)
2016-08-01T15:50:38.955866+00:00 app[web.1]: at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
2016-08-01T15:50:38.955868+00:00 app[web.1]: at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
2016-08-01T15:50:38.955866+00:00 app[web.1]: at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
2016-08-01T15:50:38.955865+00:00 app[web.1]: at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
I'm not sure where to begin with this. Nor am I certain that it is a problem with ring-json. Do I perhaps need to set the headers somewhere?
Any help would be greatly appreciated. Temporarily, here is a link to the project running on heroku: https://esd-viz.herokuapp.com/. The project itself can be found at http://github.com/ezmiller/esd-viz.
lein uberjar
heroku local web
Runs the stack from the Procfile which will be the best way to test things locally. (hosts on port 5000 by default). This reproduces the problem for me.
As to the cause... the problem is here:
33 (def load-data
34 {:status 200
35 :body (essdata/get-json-data)})
The body you are returning is a vector, which is not valid unless you have middleware to handle it. So are the ring-defaults set up correctly?
If you compare:
env/dev/clj/esd_viz/middleware.clj
env/prod/clj/esd_viz/middleware.clj
You can see that in dev you have JSON middleware, but not in prod.
Hence when running with the prod profile, the vector is not converted to JSON like it is in dev.