Interactive Development with ring 0.2 and compojure 0.4

6 views
Skip to first unread message

Rick Moynihan

unread,
Mar 22, 2010, 10:21:48 AM3/22/10
to comp...@googlegroups.com, ring-c...@googlegroups.com
Hi all,

I've been taking a look at compojure 0.4, and have been having some
trouble getting started.

It appears that the new method of web server is to use ring's
adapters, as the 0.4 branch seems to have removed the jetty-server
function.

No bother, as ring supplies ring.adapter.jetty/run-jetty function,
unfortunately though it's behaviour doesn't seem to encourage lisp
style interactive development.

I have the following code taken from rings hello_world example:

(ns ring.example.hello-world
(:use ring.adapter.jetty)
(:import java.util.Date java.text.SimpleDateFormat))

(defn app
[req]
{:status 200
:headers {"Content-Type" "text/html"}
:body (str "<h3>Hello World from Ring</h3>"
"<p>The current time is "
(.format (SimpleDateFormat. "HH:mm:ss") (Date.))
".</p>")})

(run-jetty app {:port 8080})

Running this code works, however once its running modifying the
definition of the app function (e.g. changing it to say "Hello Rick")
and re-evaluating the form in Emacs/SLIME doesn't cause the changes to
propogate into Jetty. Also re-evaluating the whole file fails as
jetty's socket is left open.

I believe the ability to redefine functions and have them
automagically be deployed was a feature of Compojure 0.3.2. What is
the preferred way to do this now?

Thanks for your help,

R.

p.s. I hope you don't mind the cross-post, but I'm not sure where this
responsibilty lies...

Mark McGranaghan

unread,
Mar 22, 2010, 12:46:02 PM3/22/10
to Ring
Hi Rick,

Sorry to hear that you've been having trouble. You might find the
following helpful:

http://groups.google.com/group/clojure/browse_thread/thread/de68fbae18bec572/022a828bf0bd3cf7#022a828bf0bd3cf7

The short answer is that (run-jetty (var app)) will solve your
problem.

Let me know if you have any other difficulties with reloading.

- Mark

Rick Moynihan

unread,
Mar 22, 2010, 1:49:02 PM3/22/10
to ring-c...@googlegroups.com
On 22 March 2010 16:46, Mark McGranaghan <mmcg...@gmail.com> wrote:
> Hi Rick,
>
> Sorry to hear that you've been having trouble. You might find the
> following helpful:
>
> http://groups.google.com/group/clojure/browse_thread/thread/de68fbae18bec572/022a828bf0bd3cf7#022a828bf0bd3cf7
>
> The short answer is that (run-jetty (var app)) will solve your
> problem.

Thanks a lot for this!

R.

Scott Jaderholm

unread,
May 22, 2010, 3:07:26 AM5/22/10
to comp...@googlegroups.com, ring-c...@googlegroups.com
What do you think about changing the line

(run-jetty example {:port 8080})

to

(run-jetty (var example) {:port 8080})

at http://weavejester.github.com/compojure/docs/getting-started.html ?

See http://groups.google.com/group/ring-clojure/browse_thread/thread/5606760b86cfd49c/f2be9cf207cf0f11?lnk=gst&q=interactive
(the reply to this thread that didn't make it to compojure ml) for
details about why this is important.

Is this something that should only be done in development or is it
fine for production?

Not knowing about this caused me a lot of frustration when trying to
converting a 0.3.2 app to 0.4.0 and my changes weren't taking effect.
I suspect it others will expect (and want) the old interactive
behavior as well.

Also, what's the proper way to stop the server with 0.4.0? The code
for run-jetty makes it look like it returns the server s, but when i
call run-jetty so long as the server is running that function doesn't
return so I don't get an #^Server s to call .stop (a method I assume
exists) on.

Thanks,
Scott
> --
> You received this message because you are subscribed to the Google Groups "Compojure" group.
> To post to this group, send email to comp...@googlegroups.com.
> To unsubscribe from this group, send email to compojure+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/compojure?hl=en.
>
>
Reply all
Reply to author
Forward
0 new messages