-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmigration.html
93 lines (79 loc) · 3.07 KB
/
migration.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
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/varnish/hitch">Hitch</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.3.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.route :as route]
[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 %}