You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><code>run-server</code> starts a Ring-compatible HTTP server, <ahref="#routing">routing using compojure</a></p>
{% highlight clojure %}
(defn app [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "hello HTTP!"})
(run-server app {:port 8080})
{% endhighlight %}
<h4>Options:</h4>
<ul>
<li><code>:ip</code>: which IP to bind, default to <code>0.0.0.0</code></li>
<li><code>:port</code>: which port listens incomming request, default to 8090</li>
<li><code>:thread</code>: How many threads to compute response from request, default to 4</li>
<li><code>:worker-name-prefix</code>: woker thread name prefix, default to <code>worker-</code>: <code>worker-1</code><code>worker-2</code>....</li>
<li><code>:queue-size</code>: max requests queued waiting for threadpool to compute response before reject, 503(Service Unavailable) is returned to client if queue is full, default to 20K</li>
<li><code>:max-body</code>: length limit for request body in bytes, 413(Request Entity Too Large) is returned if exceeds this limit, default to 8388608(8M)</li>
<li><code>:max-line</code>: length limit for HTTP inital line and per header,
414(Request-URI Too Long) will be returned if exceeds this limit, default to 4096(4K),
<ahref="http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url">relevant discusstion on stackoverflow</a></li>
<code>if-ws-request</code> or <code>when-ws-request</code>: get the websocket connection, returns websocket handshake
</li>
<li><code>on-mesg</code>: register a fn to be called when there is string message from client</li>
<li><code>send-mesg</code>: send string message to client. <i>Clojure data can be converted to string using
<ahref="https://github.com/clojure/data.json">JSON</a> or <ahref="https://github.com/edn-format/edn">edn</a></i></li>
<li><code>close-conn</code>: close the websocket connection</li>
<li><code>on-close</code>: register a fn to be called when the connecton is closed</li>
</ul>
<p>For WebSocket Secure connection, one option is <ahref="https://github.com/bumptech/stud">stud</a> (self-signed certificate may not work with websocket)</p>
(route/not-found "<p>Page not found.</p>")) ;; all other, return 404
(run-server (site #'all-routes) {:port 8080})
{% endhighlight %}
<h3class="anchor" id="deploy">Recommended server deployment</h3>
<p>http-kit runs alone happly, handy for development and quick deployment.
Use reverse proxy like <ahref="http://wiki.nginx.org/Main">Nginx</a>,
<ahref="http://www.lighttpd.net/">Lighthttpd</a>, etc in serious production is encouraged. They also <ahref="migration.html#https">add https support</a>.</p>
<ul>
<li>They are fast, heavily optimized for static content.</li>
<li>They can be configured to compress the content sent to browsers</li>