Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (78 sloc) 3.1 kb
---
layout: doc
title: Migration from Jetty
---
<h2>Migrate from Ring Jetty adapter</h2>
<p>
HTTP Kit is an almost drop-in
replacement for the standard Ring Jetty adapter,
just replace <code>run-jetty</code> with <code>run-server</code>.
</p>
<p>Few differences:</p>
<h3 class="anchor" id="stop">Stop server programmatically</h3>
{% highlight clojure %}
(let [jetty (run-jetty app options)]
(.stop jetty))
(let [server (run-server app options)]
;; run-server returns a function that stops the server
(server))
{% endhighlight %}
<h3 class="anchor" id="https">Configuring HTTPS</h3>
<p>
http-kit relies on reverse proxy (like <a href="http://wiki.nginx.org/HttpSslModule">Nginx</a>, <a href="http://redmine.lighttpd.net/projects/1/wiki/Docs_SSL">Lighthttpd</a>) to support HTTPS. <i>They also can be used as a <a href="server.html#deploy">reverse proxy to serve static files and compress content.</a></i>
</p>
<p>
<a href="https://github.com/bumptech/stud">Stud</a> is another option. It works well with websockets and long polling.
</p>
<p>Sample configration for Nginx: </p>
{% highlight sh %}
server {
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/ssl/xxxxx_ssl.crt;
ssl_certificate_key /etc/nginx/ssl/xxxx_ssl.key.nopasswd;
location / {
# http-kit listens on port 9090
proxy_pass http://127.0.0.1:9090/;
proxy_set_header Host $http_host;
}
}
{% endhighlight %}
</p>
<h3 class="anchor" id="reload">Hot code reload (lein ring server)</h3>
<p>Hot code reload is very handy, with the Jetty one you can do something like:</p>
{% highlight sh %}
lein ring server # https://github.com/weavejester/lein-ring
{% endhighlight %}
<p>lein-ring does not yet support http-kit, but
<code>ring.middleware.reload</code> can be used as a workaround.</p>
{% highlight sh %}
lein run # start a server in :8080, hot code reload
{% endhighlight %}
{% highlight clojure %}
;; project.clj
(defproject xxxx "1.0.1"
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.1.5"]
[ring/ring-devel "1.1.8"]
[ring/ring-core "1.1.8"]
[http-kit "2.0.0"]]
; allow lein run to find a place to start
:main clj_web.main)
;; src/clj_web/main.clj
(ns clj_web.main
(:use [org.httpkit.server :only [run-server]])
(:require [ring.middleware.reload :as reload]
[compojure.handler :refer [site]]
[compojure.core :refer [defroutes GET POST]]))
(defroutes all-routes
(GET "/" [] "handling-page")
(GET "/save" [] handler) ;; websocket
(route/not-found "<p>Page not found.</p>")) ;; all other, return 404
(defn in-dev? true) ;; TODO read a config variable from command line, env, or file?
(defn -main [& args] ;; entry point, lein run will pick up and start from here
(let [handler (if (in-dev? args)
(reload/wrap-reload (site #'all-routes)) ;; only reload when dev
(site all-routes))]
(run-server handler {:port 8080})))
{% endhighlight %}
Jump to Line
Something went wrong with that request. Please try again.