compojure

How to run an arbitrary startup function in a ring project?

99封情书 提交于 2019-11-30 01:29:26
问题 I've got a compojure/ring application I currently run with lein ring server that I'd like to compile to a .war so I can deploy it. I've got a definition, however, just like (def foo (start-scheduler)) That blocks the compilation and the generation of the .war. To circumvent this, I thought about moving the call to a startup function, but how would I call it when the server launches? If I put the call inside the handler, I'd end up with the same problem as before. Thanks! 回答1: In your project

What's the “big idea” behind compojure routes?

情到浓时终转凉″ 提交于 2019-11-29 18:33:41
I'm new to Clojure and have been using Compojure to write a basic web application. I'm hitting a wall with Compojure's defroutes syntax, though, and I think I need to understand both the "how" and the "why" behind it all. It seems like a Ring-style application begins with an HTTP request map, then just passes the request through a series of middleware functions until it gets transformed into a response map, which gets sent back to the browser. This style seems too "low level" for developers, thus the need for a tool like Compojure. I can see this need for more abstractions in other software

Serve index.html at / by default in Compojure

元气小坏坏 提交于 2019-11-29 00:31:24
问题 I have a static file called index.html that I'd like to serve when someone requests / . Usually web servers do this by default, but Compojure doesn't. How can I make Compojure serve index.html when someone requests / ? Here's the code I'm using for the static directory: ; match anything in the static dir at resources/public (route/resources "/") 回答1: This would be a pretty simple Ring middleware: (defn wrap-dir-index [handler] (fn [req] (handler (update-in req [:uri] #(if (= "/" %) "/index

Compojure development without web server restarts

喜你入骨 提交于 2019-11-28 15:23:31
I've written a small Swing App before in Clojure and now I'd like to create an Ajax-style Web-App. Compojure looks like the best choice right now, so that's what I'm going to try out. I'd like to have a real tiny edit/try feedback-loop, so I'd prefer not to restart the web server after each small change I do. What's the best way to accomplish this? By default my Compojure setup (the standard stuff with ant deps/ant with Jetty) doesn't seem to reload any changes I do. I'll have to restart with run-server to see the changes. Because of the Java-heritage and the way the system is started etc.

What's the “big idea” behind compojure routes?

自闭症网瘾萝莉.ら 提交于 2019-11-28 13:09:06
问题 I'm new to Clojure and have been using Compojure to write a basic web application. I'm hitting a wall with Compojure's defroutes syntax, though, and I think I need to understand both the "how" and the "why" behind it all. It seems like a Ring-style application begins with an HTTP request map, then just passes the request through a series of middleware functions until it gets transformed into a response map, which gets sent back to the browser. This style seems too "low level" for developers,

Compojure/Ring: Why doesn't a session with cookie-store survive a server restart?

ⅰ亾dé卋堺 提交于 2019-11-27 23:50:57
问题 I have a compojure app that uses the ring session wrapper to store the OAuth token associated with the current user. I would like for this token to remain available when the server restarts, so that I don't have to go through the auth process each time. I assumed that using the cookie-store instead of the default memory-store would help, but it does not. What am I missing? This is the relevant part of the code: (defn auth-callback-handler [session {code :code}] (let [token (retrieve-token

Compojure development without web server restarts

我的未来我决定 提交于 2019-11-27 09:12:52
问题 I've written a small Swing App before in Clojure and now I'd like to create an Ajax-style Web-App. Compojure looks like the best choice right now, so that's what I'm going to try out. I'd like to have a real tiny edit/try feedback-loop, so I'd prefer not to restart the web server after each small change I do. What's the best way to accomplish this? By default my Compojure setup (the standard stuff with ant deps/ant with Jetty) doesn't seem to reload any changes I do. I'll have to restart with

Serving static files with ring/compojure - from a war

醉酒当歌 提交于 2019-11-26 20:55:10
问题 Using ring (and the lein-ring tools) - I am able to serve up static files from "resources" etc as per the docs when running in development - however - when I package things up via lien uberwar I have no idea how to make it serve those files when running in a container. I see conflicting docs on wrap-resource, or setting :resource-path but none seem to work. 回答1: As per Compojure's Getting Started Wiki, put route/resources below your paths: (defroutes main-routes (GET "/" [] "<h1>Hello World