Fork me on GitHub
#beginners
<
2018-08-22
>
gaverhae00:08:06

The convention used by Compojure is that all (most?) of its helper functions and macros like GET, POST, resources, files, etc. are ultimately Ring handlers, with the small difference that they have the option of returning nil as a way to say "look at the next handler instead"

gaverhae00:08:16

(which is what routes relies on)

gaverhae00:08:47

That's how you can go (routes (GET ...) (GET ...)) because GET will return nil if the request doesn't match

gaverhae00:08:58

Anyway, bottom line is resources returns a ring handler

gaverhae00:08:06

which means you can apply middleware to it

gaverhae00:08:46

So something like this should work out for your case here:

(undocumented
  (fn [req] (let [resp ((route/resources "/") req)]
              (update resp :headers merge {"Cache" ...})))

shrimpywu00:08:51

Thank you @gaverhae! Wish the API doc mention this 🙂

gaverhae11:08:43

Note that if resources is not the last handler in the compojure chain, you'll probably want to turn that let into a when-let so as not to break the convention.

its.ramzi16:08:03

Hello. I am trying to create a new default Reagent app. Then I would like to know how to produce a static HTML page and a minified JS script that I could host in Tomcat. It sounds easy, but this has proven very difficult for me. Could someone walk me through the build process for deploying to production? Thanks.

its.ramzi16:08:58

Saving the HTML page puts a lot of extra figwheel stuff in that I don't want. There needs to be a better way to produce static HTML.

its.ramzi16:08:32

And it seems that my on-change events aren't getting in for some reason. I'm pretty confused. That's why I would just like to work with someone, going from a default Reagent app to deploying it in Tomcat. Thanks.

sb17:08:35

Hi, I would like to use ssh-copy-id command from Clojure. If I run this command (sh "bash" "-c" "ssh-copy-id -i /Users/sb/.ssh/id_rsa.pub [email protected]") then I need send a password too. With echo password | command don’t want to work. Any idea how to solve in Clojure, send a password in the session?

manutter5117:08:15

maybe use ssh-agent along with it?

manutter5117:08:33

in your bash shell, I mean

sb17:08:01

@manutter51 i check it

gaverhae18:08:32

@its.ramzi Have you taken a look at tenzing? It's a template to do static clojurescript apps, so should be a fairly good fit given your description. http://martinklepsch.github.io/tenzing/

its.ramzi21:08:32

When trying to use uberwar, I run into this error: ava.io.FileNotFoundException: Could not locate ring/middleware/cors__init.class or ring/middleware/cors.clj on classpath.

its.ramzi21:08:38

Any idea how to resolve it?

seancorfield22:08:53

@its.ramzi Hard to say without more detail -- how are you specifying middleware dependencies in your project? Are you using lein, boot, or the new clj stuff? How are you creating your JAR/WAR file? Have you tested running the app in a REPL locally? (highly recommended -- Clojure can specifically avoid the compile-deploy-test cycle of other languages by letting you compile and run code directly and interactively in the REPL)

seancorfield22:08:47

(why are you creating a WAR file anyway? that's not a common path for web app deployment in Clojure -- there are definitely easier, more idiomatic ways)

its.ramzi23:08:10

@seancorfield I was using lein. Lein uberwar. The Reagent app comes out of the box as deployable with figwheel; I just don't know how to do a production deployment. I want to replace the GUI using Clojurescript, but keep the Java/Hibernate/Postgres backend that is in place. So I wanted to create a .war file that is deployable in Tomcat or Wildfly.